Updated to Drupal 8.6.4, which is PHP 7.3 friendly. Also updated HTMLaw library....
[yaffs-website] / web / core / modules / ckeditor / src / Plugin / CKEditorPlugin / DrupalImageCaption.php
1 <?php
2
3 namespace Drupal\ckeditor\Plugin\CKEditorPlugin;
4
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;
10
11 /**
12  * Defines the "drupalimagecaption" plugin.
13  *
14  * @CKEditorPlugin(
15  *   id = "drupalimagecaption",
16  *   label = @Translation("Drupal image caption widget"),
17  *   module = "ckeditor"
18  * )
19  */
20 class DrupalImageCaption extends PluginBase implements CKEditorPluginInterface, CKEditorPluginContextualInterface, CKEditorPluginCssInterface {
21
22   /**
23    * {@inheritdoc}
24    */
25   public function isInternal() {
26     return FALSE;
27   }
28
29   /**
30    * {@inheritdoc}
31    */
32   public function getDependencies(Editor $editor) {
33     return [];
34   }
35
36   /**
37    * {@inheritdoc}
38    */
39   public function getLibraries(Editor $editor) {
40     return [
41       'ckeditor/drupal.ckeditor.plugins.drupalimagecaption',
42     ];
43   }
44
45   /**
46    * {@inheritdoc}
47    */
48   public function getFile() {
49     return drupal_get_path('module', 'ckeditor') . '/js/plugins/drupalimagecaption/plugin.js';
50   }
51
52   /**
53    * {@inheritdoc}
54    */
55   public function getConfig(Editor $editor) {
56     $format = $editor->getFilterFormat();
57     return [
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,
65     ];
66   }
67
68   /**
69    * {@inheritdoc}
70    */
71   public function getCssFiles(Editor $editor) {
72     return [
73       drupal_get_path('module', 'ckeditor') . '/css/plugins/drupalimagecaption/ckeditor.drupalimagecaption.css',
74     ];
75   }
76
77   /**
78    * {@inheritdoc}
79    */
80   public function isEnabled(Editor $editor) {
81     if (!$editor->hasAssociatedFilterFormat()) {
82       return FALSE;
83     }
84
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) {
90       $enabled = FALSE;
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') {
96               $enabled = TRUE;
97             }
98           }
99         }
100       }
101       return $enabled;
102     }
103
104     return FALSE;
105   }
106
107 }