Updated to Drupal 8.6.4, which is PHP 7.3 friendly. Also updated HTMLaw library....
[yaffs-website] / web / core / modules / ckeditor / src / Plugin / CKEditorPlugin / DrupalImage.php
1 <?php
2
3 namespace Drupal\ckeditor\Plugin\CKEditorPlugin;
4
5 use Drupal\ckeditor\CKEditorPluginBase;
6 use Drupal\ckeditor\CKEditorPluginConfigurableInterface;
7 use Drupal\Core\Form\FormStateInterface;
8 use Drupal\editor\Entity\Editor;
9
10 /**
11  * Defines the "drupalimage" plugin.
12  *
13  * @CKEditorPlugin(
14  *   id = "drupalimage",
15  *   label = @Translation("Image"),
16  *   module = "ckeditor"
17  * )
18  */
19 class DrupalImage extends CKEditorPluginBase implements CKEditorPluginConfigurableInterface {
20
21   /**
22    * {@inheritdoc}
23    */
24   public function getFile() {
25     return drupal_get_path('module', 'ckeditor') . '/js/plugins/drupalimage/plugin.js';
26   }
27
28   /**
29    * {@inheritdoc}
30    */
31   public function getLibraries(Editor $editor) {
32     return [
33       'core/drupal.ajax',
34     ];
35   }
36
37   /**
38    * {@inheritdoc}
39    */
40   public function getConfig(Editor $editor) {
41     return [
42       'drupalImage_dialogTitleAdd' => $this->t('Insert Image'),
43       'drupalImage_dialogTitleEdit' => $this->t('Edit Image'),
44     ];
45   }
46
47   /**
48    * {@inheritdoc}
49    */
50   public function getButtons() {
51     return [
52       'DrupalImage' => [
53         'label' => $this->t('Image'),
54         'image' => drupal_get_path('module', 'ckeditor') . '/js/plugins/drupalimage/icons/drupalimage.png',
55       ],
56     ];
57   }
58
59   /**
60    * {@inheritdoc}
61    *
62    * @see \Drupal\editor\Form\EditorImageDialog
63    * @see editor_image_upload_settings_form()
64    */
65   public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
66     $form_state->loadInclude('editor', 'admin.inc');
67     $form['image_upload'] = editor_image_upload_settings_form($editor);
68     $form['image_upload']['#attached']['library'][] = 'ckeditor/drupal.ckeditor.drupalimage.admin';
69     $form['image_upload']['#element_validate'][] = [$this, 'validateImageUploadSettings'];
70     return $form;
71   }
72
73   /**
74    * #element_validate handler for the "image_upload" element in settingsForm().
75    *
76    * Moves the text editor's image upload settings from the DrupalImage plugin's
77    * own settings into $editor->image_upload.
78    *
79    * @see \Drupal\editor\Form\EditorImageDialog
80    * @see editor_image_upload_settings_form()
81    */
82   public function validateImageUploadSettings(array $element, FormStateInterface $form_state) {
83     $settings = &$form_state->getValue(['editor', 'settings', 'plugins', 'drupalimage', 'image_upload']);
84     $form_state->get('editor')->setImageUploadSettings($settings);
85     $form_state->unsetValue(['editor', 'settings', 'plugins', 'drupalimage']);
86   }
87
88 }