image_upload = isset($editor->image_upload) ? $editor->image_upload : array(); $editor->image_upload += array( 'status' => FALSE, 'scheme' => file_default_scheme(), 'directory' => 'inline-images', 'max_size' => '', 'max_dimensions' => array('width' => '', 'height' => ''), ); $form['status'] = array( '#type' => 'checkbox', '#title' => t('Enable image uploads'), '#default_value' => $editor->image_upload['status'], '#attributes' => array( 'data-editor-image-upload' => 'status', ), ); $show_if_image_uploads_enabled = array( 'visible' => array( ':input[data-editor-image-upload="status"]' => array('checked' => TRUE), ), ); // Any visible, writable wrapper can potentially be used for uploads, // including a remote file system that integrates with a CDN. $stream_wrappers = file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE); foreach ($stream_wrappers as $scheme => $info) { $options[$scheme] = $info['description']; } if (!empty($options)) { $form['scheme'] = array( '#type' => 'radios', '#title' => t('File storage'), '#default_value' => $editor->image_upload['scheme'], '#options' => $options, '#states' => $show_if_image_uploads_enabled, '#access' => count($options) > 1, ); } // Set data- attributes with human-readable names for all possible stream // wrappers, so that drupal.ckeditor.drupalimage.admin's summary rendering // can use that. foreach ($stream_wrappers as $scheme => $info) { $form['scheme'][$scheme]['#attributes']['data-label'] = t('Storage: @name', array('@name' => $info['name'])); } $form['directory'] = array( '#type' => 'textfield', '#default_value' => $editor->image_upload['directory'], '#title' => t('Upload directory'), '#description' => t("A directory relative to Drupal's files directory where uploaded images will be stored."), '#states' => $show_if_image_uploads_enabled, ); $default_max_size = format_size(file_upload_max_size()); $form['max_size'] = array( '#type' => 'textfield', '#default_value' => $editor->image_upload['max_size'], '#title' => t('Maximum file size'), '#description' => t('If this is left empty, then the file size will be limited by the PHP maximum upload size of @size.', array('@size' => $default_max_size)), '#maxlength' => 20, '#size' => 10, '#placeholder' => $default_max_size, '#states' => $show_if_image_uploads_enabled, ); $form['max_dimensions'] = array( '#type' => 'item', '#title' => t('Maximum dimensions'), '#field_prefix' => '
', '#field_suffix' => '
', '#description' => t('Images larger than these dimensions will be scaled down.'), '#states' => $show_if_image_uploads_enabled, ); $form['max_dimensions']['width'] = array( '#title' => t('Width'), '#title_display' => 'invisible', '#type' => 'number', '#default_value' => (empty($editor->image_upload['max_dimensions']['width'])) ? '' : $editor->image_upload['max_dimensions']['width'], '#size' => 8, '#maxlength' => 8, '#min' => 1, '#max' => 99999, '#placeholder' => t('width'), '#field_suffix' => ' x ', '#states' => $show_if_image_uploads_enabled, ); $form['max_dimensions']['height'] = array( '#title' => t('Height'), '#title_display' => 'invisible', '#type' => 'number', '#default_value' => (empty($editor->image_upload['max_dimensions']['height'])) ? '' : $editor->image_upload['max_dimensions']['height'], '#size' => 8, '#maxlength' => 8, '#min' => 1, '#max' => 99999, '#placeholder' => t('height'), '#field_suffix' => t('pixels'), '#states' => $show_if_image_uploads_enabled, ); $form['#element_validate'] = array( 'editor_image_upload_settings_validate', ); return $form; } /** * #element_validate handler for editor_image_upload_settings_validate(). * * Ensures each form item's value is cast to the proper type. * * @see \Drupal\editor\Form\EditorImageDialog * @ingroup forms */ function editor_image_upload_settings_validate(array $element, array &$form_state) { $cast_value = function($type, $element) use (&$form_state) { $section = $element['#parents']; $value = NestedArray::getValue($form_state['values'], $section); settype($value, $type); NestedArray::setValue($form_state['values'], $section, $value); }; $cast_value('bool', $element['status']); $cast_value('int', $element['max_dimensions']['width']); $cast_value('int', $element['max_dimensions']['height']); }