Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /**
|
Chris@0
|
4 * @file
|
Chris@0
|
5 * Administration functions for editor.module.
|
Chris@0
|
6 */
|
Chris@0
|
7
|
Chris@18
|
8 use Drupal\Component\Utility\Environment;
|
Chris@0
|
9 use Drupal\Core\StreamWrapper\StreamWrapperInterface;
|
Chris@0
|
10 use Drupal\editor\Entity\Editor;
|
Chris@0
|
11
|
Chris@0
|
12 /**
|
Chris@0
|
13 * Subform constructor to configure the text editor's image upload settings.
|
Chris@0
|
14 *
|
Chris@0
|
15 * Each text editor plugin that is configured to offer the ability to insert
|
Chris@0
|
16 * images and uses EditorImageDialog for that, should use this form to update
|
Chris@0
|
17 * the text editor's configuration so that EditorImageDialog knows whether it
|
Chris@0
|
18 * should allow the user to upload images.
|
Chris@0
|
19 *
|
Chris@0
|
20 * @param \Drupal\editor\Entity\Editor $editor
|
Chris@0
|
21 * The text editor entity that is being edited.
|
Chris@0
|
22 *
|
Chris@0
|
23 * @return array
|
Chris@0
|
24 * The image upload settings form.
|
Chris@0
|
25 *
|
Chris@0
|
26 * @see \Drupal\editor\Form\EditorImageDialog
|
Chris@0
|
27 */
|
Chris@0
|
28 function editor_image_upload_settings_form(Editor $editor) {
|
Chris@0
|
29 // Defaults.
|
Chris@0
|
30 $image_upload = $editor->getImageUploadSettings();
|
Chris@0
|
31 $image_upload += [
|
Chris@0
|
32 'status' => FALSE,
|
Chris@0
|
33 'scheme' => file_default_scheme(),
|
Chris@0
|
34 'directory' => 'inline-images',
|
Chris@0
|
35 'max_size' => '',
|
Chris@0
|
36 'max_dimensions' => ['width' => '', 'height' => ''],
|
Chris@0
|
37 ];
|
Chris@0
|
38
|
Chris@0
|
39 $form['status'] = [
|
Chris@0
|
40 '#type' => 'checkbox',
|
Chris@0
|
41 '#title' => t('Enable image uploads'),
|
Chris@0
|
42 '#default_value' => $image_upload['status'],
|
Chris@0
|
43 '#attributes' => [
|
Chris@0
|
44 'data-editor-image-upload' => 'status',
|
Chris@0
|
45 ],
|
Chris@0
|
46 ];
|
Chris@0
|
47 $show_if_image_uploads_enabled = [
|
Chris@0
|
48 'visible' => [
|
Chris@0
|
49 ':input[data-editor-image-upload="status"]' => ['checked' => TRUE],
|
Chris@0
|
50 ],
|
Chris@0
|
51 ];
|
Chris@0
|
52
|
Chris@0
|
53 // Any visible, writable wrapper can potentially be used for uploads,
|
Chris@0
|
54 // including a remote file system that integrates with a CDN.
|
Chris@0
|
55 $options = \Drupal::service('stream_wrapper_manager')->getDescriptions(StreamWrapperInterface::WRITE_VISIBLE);
|
Chris@0
|
56 if (!empty($options)) {
|
Chris@0
|
57 $form['scheme'] = [
|
Chris@0
|
58 '#type' => 'radios',
|
Chris@0
|
59 '#title' => t('File storage'),
|
Chris@0
|
60 '#default_value' => $image_upload['scheme'],
|
Chris@0
|
61 '#options' => $options,
|
Chris@0
|
62 '#states' => $show_if_image_uploads_enabled,
|
Chris@0
|
63 '#access' => count($options) > 1,
|
Chris@0
|
64 ];
|
Chris@0
|
65 }
|
Chris@0
|
66 // Set data- attributes with human-readable names for all possible stream
|
Chris@0
|
67 // wrappers, so that drupal.ckeditor.drupalimage.admin's summary rendering
|
Chris@0
|
68 // can use that.
|
Chris@0
|
69 foreach (\Drupal::service('stream_wrapper_manager')->getNames(StreamWrapperInterface::WRITE_VISIBLE) as $scheme => $name) {
|
Chris@0
|
70 $form['scheme'][$scheme]['#attributes']['data-label'] = t('Storage: @name', ['@name' => $name]);
|
Chris@0
|
71 }
|
Chris@0
|
72
|
Chris@0
|
73 $form['directory'] = [
|
Chris@0
|
74 '#type' => 'textfield',
|
Chris@0
|
75 '#default_value' => $image_upload['directory'],
|
Chris@0
|
76 '#title' => t('Upload directory'),
|
Chris@0
|
77 '#description' => t("A directory relative to Drupal's files directory where uploaded images will be stored."),
|
Chris@0
|
78 '#states' => $show_if_image_uploads_enabled,
|
Chris@0
|
79 ];
|
Chris@0
|
80
|
Chris@18
|
81 $default_max_size = format_size(Environment::getUploadMaxSize());
|
Chris@0
|
82 $form['max_size'] = [
|
Chris@0
|
83 '#type' => 'textfield',
|
Chris@0
|
84 '#default_value' => $image_upload['max_size'],
|
Chris@0
|
85 '#title' => t('Maximum file size'),
|
Chris@0
|
86 '#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]),
|
Chris@0
|
87 '#maxlength' => 20,
|
Chris@0
|
88 '#size' => 10,
|
Chris@0
|
89 '#placeholder' => $default_max_size,
|
Chris@0
|
90 '#states' => $show_if_image_uploads_enabled,
|
Chris@0
|
91 ];
|
Chris@0
|
92
|
Chris@0
|
93 $form['max_dimensions'] = [
|
Chris@0
|
94 '#type' => 'item',
|
Chris@0
|
95 '#title' => t('Maximum dimensions'),
|
Chris@0
|
96 '#field_prefix' => '<div class="container-inline clearfix">',
|
Chris@0
|
97 '#field_suffix' => '</div>',
|
Chris@0
|
98 '#description' => t('Images larger than these dimensions will be scaled down.'),
|
Chris@0
|
99 '#states' => $show_if_image_uploads_enabled,
|
Chris@0
|
100 ];
|
Chris@0
|
101 $form['max_dimensions']['width'] = [
|
Chris@0
|
102 '#title' => t('Width'),
|
Chris@0
|
103 '#title_display' => 'invisible',
|
Chris@0
|
104 '#type' => 'number',
|
Chris@0
|
105 '#default_value' => (empty($image_upload['max_dimensions']['width'])) ? '' : $image_upload['max_dimensions']['width'],
|
Chris@0
|
106 '#size' => 8,
|
Chris@0
|
107 '#maxlength' => 8,
|
Chris@0
|
108 '#min' => 1,
|
Chris@0
|
109 '#max' => 99999,
|
Chris@0
|
110 '#placeholder' => t('width'),
|
Chris@0
|
111 '#field_suffix' => ' x ',
|
Chris@0
|
112 '#states' => $show_if_image_uploads_enabled,
|
Chris@0
|
113 ];
|
Chris@0
|
114 $form['max_dimensions']['height'] = [
|
Chris@0
|
115 '#title' => t('Height'),
|
Chris@0
|
116 '#title_display' => 'invisible',
|
Chris@0
|
117 '#type' => 'number',
|
Chris@0
|
118 '#default_value' => (empty($image_upload['max_dimensions']['height'])) ? '' : $image_upload['max_dimensions']['height'],
|
Chris@0
|
119 '#size' => 8,
|
Chris@0
|
120 '#maxlength' => 8,
|
Chris@0
|
121 '#min' => 1,
|
Chris@0
|
122 '#max' => 99999,
|
Chris@0
|
123 '#placeholder' => t('height'),
|
Chris@0
|
124 '#field_suffix' => t('pixels'),
|
Chris@0
|
125 '#states' => $show_if_image_uploads_enabled,
|
Chris@0
|
126 ];
|
Chris@0
|
127
|
Chris@0
|
128 return $form;
|
Chris@0
|
129 }
|