annotate core/modules/editor/editor.admin.inc @ 2:5311817fb629

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