EditorAdvancedImage.php in Editor Advanced Image 8.2
File
src/Plugin/CKEditorPlugin/EditorAdvancedImage.php
View source
<?php
namespace Drupal\editor_advanced_image\Plugin\CKEditorPlugin;
use Drupal\Core\Plugin\PluginBase;
use Drupal\editor\Entity\Editor;
use Drupal\ckeditor\CKEditorPluginInterface;
use Drupal\ckeditor\CKEditorPluginContextualInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\ckeditor\CKEditorPluginConfigurableInterface;
class EditorAdvancedImage extends PluginBase implements CKEditorPluginInterface, CKEditorPluginContextualInterface, CKEditorPluginConfigurableInterface {
public function isInternal() {
return FALSE;
}
public function getDependencies(Editor $editor) {
return [];
}
public function getLibraries(Editor $editor) {
return [
'ckeditor/drupal.ckeditor.plugins.editoradvancedimage',
];
}
public function getFile() {
return drupal_get_path('module', 'editor_advanced_image') . '/plugins/' . $this
->getPluginId() . '/plugin.js';
}
public function getConfig(Editor $editor) {
$config = [];
$settings = $editor
->getSettings();
if (!isset($settings['plugins']['editoradvancedimage']['default_class'])) {
return $config;
}
$config['defaultClasses'] = $settings['plugins']['editoradvancedimage']['default_class'];
return $config;
}
public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
$settings = $editor
->getSettings();
$form['default_class'] = [
'#title' => $this
->t('Default image class(es)'),
'#type' => 'textfield',
'#default_value' => !empty($settings['plugins']['editoradvancedimage']['default_class']) ? $settings['plugins']['editoradvancedimage']['default_class'] : '',
'#description' => $this
->t('A list of classes that will be added when the user adds an inline-image with CKEditor. <br>Enter one or more classes separated by spaces. Example: <code>img-responsive</code> or <code>img-fluid</code>.'),
];
return $form;
}
public function isEnabled(Editor $editor) {
$settings = $editor
->getSettings();
if ($this
->checkImageEnable($settings['toolbar']['rows'][0])) {
return TRUE;
}
return FALSE;
}
public function checkImageEnable(array $toolbar) {
foreach ($toolbar as $items) {
foreach ($items['items'] as $item) {
if ('DrupalImage' === $item) {
return TRUE;
}
}
}
return FALSE;
}
}