3 namespace Drupal\ckeditor\Plugin\CKEditorPlugin;
5 use Drupal\ckeditor\CKEditorPluginBase;
6 use Drupal\ckeditor\CKEditorPluginConfigurableInterface;
7 use Drupal\Core\Form\FormStateInterface;
8 use Drupal\editor\Entity\Editor;
11 * Defines the "drupalimage" plugin.
15 * label = @Translation("Image"),
19 class DrupalImage extends CKEditorPluginBase implements CKEditorPluginConfigurableInterface {
24 public function getFile() {
25 return drupal_get_path('module', 'ckeditor') . '/js/plugins/drupalimage/plugin.js';
31 public function getLibraries(Editor $editor) {
40 public function getConfig(Editor $editor) {
42 'drupalImage_dialogTitleAdd' => $this->t('Insert Image'),
43 'drupalImage_dialogTitleEdit' => $this->t('Edit Image'),
50 public function getButtons() {
53 'label' => $this->t('Image'),
54 'image' => drupal_get_path('module', 'ckeditor') . '/js/plugins/drupalimage/icons/drupalimage.png',
62 * @see \Drupal\editor\Form\EditorImageDialog
63 * @see editor_image_upload_settings_form()
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'];
74 * #element_validate handler for the "image_upload" element in settingsForm().
76 * Moves the text editor's image upload settings from the DrupalImage plugin's
77 * own settings into $editor->image_upload.
79 * @see \Drupal\editor\Form\EditorImageDialog
80 * @see editor_image_upload_settings_form()
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']);