5 * Administration functions for editor.module.
8 use Drupal\Core\StreamWrapper\StreamWrapperInterface;
9 use Drupal\editor\Entity\Editor;
12 * Subform constructor to configure the text editor's image upload settings.
14 * Each text editor plugin that is configured to offer the ability to insert
15 * images and uses EditorImageDialog for that, should use this form to update
16 * the text editor's configuration so that EditorImageDialog knows whether it
17 * should allow the user to upload images.
19 * @param \Drupal\editor\Entity\Editor $editor
20 * The text editor entity that is being edited.
23 * The image upload settings form.
25 * @see \Drupal\editor\Form\EditorImageDialog
27 function editor_image_upload_settings_form(Editor $editor) {
29 $image_upload = $editor->getImageUploadSettings();
32 'scheme' => file_default_scheme(),
33 'directory' => 'inline-images',
35 'max_dimensions' => ['width' => '', 'height' => ''],
39 '#type' => 'checkbox',
40 '#title' => t('Enable image uploads'),
41 '#default_value' => $image_upload['status'],
43 'data-editor-image-upload' => 'status',
46 $show_if_image_uploads_enabled = [
48 ':input[data-editor-image-upload="status"]' => ['checked' => TRUE],
52 // Any visible, writable wrapper can potentially be used for uploads,
53 // including a remote file system that integrates with a CDN.
54 $options = \Drupal::service('stream_wrapper_manager')->getDescriptions(StreamWrapperInterface::WRITE_VISIBLE);
55 if (!empty($options)) {
58 '#title' => t('File storage'),
59 '#default_value' => $image_upload['scheme'],
60 '#options' => $options,
61 '#states' => $show_if_image_uploads_enabled,
62 '#access' => count($options) > 1,
65 // Set data- attributes with human-readable names for all possible stream
66 // wrappers, so that drupal.ckeditor.drupalimage.admin's summary rendering
68 foreach (\Drupal::service('stream_wrapper_manager')->getNames(StreamWrapperInterface::WRITE_VISIBLE) as $scheme => $name) {
69 $form['scheme'][$scheme]['#attributes']['data-label'] = t('Storage: @name', ['@name' => $name]);
72 $form['directory'] = [
73 '#type' => 'textfield',
74 '#default_value' => $image_upload['directory'],
75 '#title' => t('Upload directory'),
76 '#description' => t("A directory relative to Drupal's files directory where uploaded images will be stored."),
77 '#states' => $show_if_image_uploads_enabled,
80 $default_max_size = format_size(file_upload_max_size());
82 '#type' => 'textfield',
83 '#default_value' => $image_upload['max_size'],
84 '#title' => t('Maximum file size'),
85 '#description' => t('If this is left empty, then the file size will be limited by the PHP maximum upload size of @size.', ['@size' => $default_max_size]),
88 '#placeholder' => $default_max_size,
89 '#states' => $show_if_image_uploads_enabled,
92 $form['max_dimensions'] = [
94 '#title' => t('Maximum dimensions'),
95 '#field_prefix' => '<div class="container-inline clearfix">',
96 '#field_suffix' => '</div>',
97 '#description' => t('Images larger than these dimensions will be scaled down.'),
98 '#states' => $show_if_image_uploads_enabled,
100 $form['max_dimensions']['width'] = [
101 '#title' => t('Width'),
102 '#title_display' => 'invisible',
104 '#default_value' => (empty($image_upload['max_dimensions']['width'])) ? '' : $image_upload['max_dimensions']['width'],
109 '#placeholder' => t('width'),
110 '#field_suffix' => ' x ',
111 '#states' => $show_if_image_uploads_enabled,
113 $form['max_dimensions']['height'] = [
114 '#title' => t('Height'),
115 '#title_display' => 'invisible',
117 '#default_value' => (empty($image_upload['max_dimensions']['height'])) ? '' : $image_upload['max_dimensions']['height'],
122 '#placeholder' => t('height'),
123 '#field_suffix' => t('pixels'),
124 '#states' => $show_if_image_uploads_enabled,