ImagePopup.php in Simple Image Popup 2.x
File
src/Plugin/CKEditorPlugin/ImagePopup.php
View source
<?php
namespace Drupal\image_popup\Plugin\CKEditorPlugin;
use Drupal\ckeditor\CKEditorPluginBase;
use Drupal\ckeditor\CKEditorPluginConfigurableInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\editor\Entity\Editor;
class ImagePopup extends CKEditorPluginBase implements CKEditorPluginConfigurableInterface {
public function isInternal() {
return FALSE;
}
public function getFile() {
return drupal_get_path('module', 'image_popup') . '/js/plugins/imagepopup/plugin.js';
}
public function getLibraries(Editor $editor) {
return [
'core/drupal.ajax',
];
}
public function getConfig(Editor $editor) {
return [
'imagePopup_dialogTitleAdd' => $this
->t('Insert Image popup'),
'imagePopup_dialogTitleEdit' => $this
->t('Edit Image popup'),
];
}
public function getButtons() {
return [
'ImagePopup' => [
'label' => $this
->t('Image Popup'),
'image' => drupal_get_path('module', 'image_popup') . '/js/plugins/imagepopup/icons/imagepopup.png',
],
];
}
public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
$form_state
->loadInclude('editor', 'admin.inc');
$form['image_upload'] = editor_image_upload_settings_form($editor);
$form['image_upload']['#attached']['library'][] = 'image_popup/image_popup.imagepopup.admin';
$form['image_upload']['#element_validate'][] = [
$this,
'validateImageUploadSettings',
];
return $form;
}
public function validateImageUploadSettings(array $element, FormStateInterface $form_state) {
$settings =& $form_state
->getValue([
'editor',
'settings',
'plugins',
'imagepopup',
'image_upload',
]);
$form_state
->get('editor')
->setImageUploadSettings($settings);
$form_state
->unsetValue([
'editor',
'settings',
'plugins',
'imagepopup',
]);
}
}