DrupalImage.php 2.61 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
<?php

/**
 * @file
 * Contains \Drupal\ckeditor\Plugin\ckeditor\plugin\DrupalImage.
 */

namespace Drupal\ckeditor\Plugin\CKEditorPlugin;

use Drupal\ckeditor\CKEditorPluginBase;
11
use Drupal\ckeditor\CKEditorPluginConfigurableInterface;
12 13
use Drupal\ckeditor\Annotation\CKEditorPlugin;
use Drupal\Core\Annotation\Translation;
14
use Drupal\editor\Entity\Editor;
15 16 17 18 19 20

/**
 * Defines the "drupalimage" plugin.
 *
 * @CKEditorPlugin(
 *   id = "drupalimage",
21
 *   label = @Translation("Image"),
22 23 24
 *   module = "ckeditor"
 * )
 */
25
class DrupalImage extends CKEditorPluginBase implements CKEditorPluginConfigurableInterface {
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

  /**
   * {@inheritdoc}
   */
  public function getFile() {
    return drupal_get_path('module', 'ckeditor') . '/js/plugins/drupalimage/plugin.js';
  }

  /**
   * {@inheritdoc}
   */
  public function getLibraries(Editor $editor) {
    return array(
      array('system', 'drupal.ajax'),
    );
  }

  /**
   * {@inheritdoc}
   */
  public function getConfig(Editor $editor) {
    return array(
      'drupalImage_dialogTitleAdd' => t('Insert Image'),
      'drupalImage_dialogTitleEdit' => t('Edit Image'),
    );
  }

  /**
   * {@inheritdoc}
   */
  public function getButtons() {
    return array(
      'DrupalImage' => array(
        'label' => t('Image'),
        'image' => drupal_get_path('module', 'ckeditor') . '/js/plugins/drupalimage/image.png',
      ),
    );
  }

65 66 67 68 69 70 71 72 73 74
  /**
   * {@inheritdoc}
   *
   * @see \Drupal\editor\Form\EditorImageDialog
   * @see editor_image_upload_settings_form()
   */
  public function settingsForm(array $form, array &$form_state, Editor $editor) {
    form_load_include($form_state, 'inc', 'editor', 'editor.admin');
    $form['image_upload'] = editor_image_upload_settings_form($editor);
    $form['image_upload']['#attached']['library'][] = array('ckeditor', 'drupal.ckeditor.drupalimage.admin');
75
    $form['image_upload']['#element_validate'][] = array($this, 'validateImageUploadSettings');
76 77 78 79 80 81 82 83 84 85 86
    return $form;
  }

  /**
   * #element_validate handler for the "image_upload" element in settingsForm().
   *
   * Moves the text editor's image upload settings from the DrupalImage plugin's
   * own settings into $editor->image_upload.
   *
   * @see \Drupal\editor\Form\EditorImageDialog
   * @see editor_image_upload_settings_form()
87
   * @see editor_image_upload_settings_validate()
88 89 90 91 92 93 94
   */
  function validateImageUploadSettings(array $element, array &$form_state) {
    $settings = &$form_state['values']['editor']['settings']['plugins']['drupalimage']['image_upload'];
    $form_state['editor']->image_upload = $settings;
    unset($form_state['values']['editor']['settings']['plugins']['drupalimage']);
  }

95
}