3 namespace Drupal\ckeditor\Plugin\CKEditorPlugin;
5 use Drupal\Core\Plugin\PluginBase;
6 use Drupal\editor\Entity\Editor;
7 use Drupal\ckeditor\CKEditorPluginInterface;
8 use Drupal\ckeditor\CKEditorPluginContextualInterface;
9 use Drupal\ckeditor\CKEditorPluginCssInterface;
12 * Defines the "drupalimagecaption" plugin.
15 * id = "drupalimagecaption",
16 * label = @Translation("Drupal image caption widget"),
20 class DrupalImageCaption extends PluginBase implements CKEditorPluginInterface, CKEditorPluginContextualInterface, CKEditorPluginCssInterface {
25 public function isInternal() {
32 public function getDependencies(Editor $editor) {
39 public function getLibraries(Editor $editor) {
41 'ckeditor/drupal.ckeditor.plugins.drupalimagecaption',
48 public function getFile() {
49 return drupal_get_path('module', 'ckeditor') . '/js/plugins/drupalimagecaption/plugin.js';
55 public function getConfig(Editor $editor) {
56 $format = $editor->getFilterFormat();
58 'image2_captionedClass' => 'caption caption-img',
59 'image2_alignClasses' => ['align-left', 'align-center', 'align-right'],
60 'drupalImageCaption_captionPlaceholderText' => $this->t('Enter caption here'),
61 // Only enable those parts of DrupalImageCaption for which the
62 // corresponding Drupal text filters are enabled.
63 'drupalImageCaption_captionFilterEnabled' => $format->filters('filter_caption')->status,
64 'drupalImageCaption_alignFilterEnabled' => $format->filters('filter_align')->status,
71 public function getCssFiles(Editor $editor) {
73 drupal_get_path('module', 'ckeditor') . '/css/plugins/drupalimagecaption/ckeditor.drupalimagecaption.css'
80 public function isEnabled(Editor $editor) {
81 if (!$editor->hasAssociatedFilterFormat()) {
85 // Automatically enable this plugin if the text format associated with this
86 // text editor uses the filter_align or filter_caption filter and the
87 // DrupalImage button is enabled.
88 $format = $editor->getFilterFormat();
89 if ($format->filters('filter_align')->status || $format->filters('filter_caption')->status) {
91 $settings = $editor->getSettings();
92 foreach ($settings['toolbar']['rows'] as $row) {
93 foreach ($row as $group) {
94 foreach ($group['items'] as $button) {
95 if ($button === 'DrupalImage') {