Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / ckeditor / tests / modules / src / Plugin / CKEditorPlugin / LlamaContextualAndButton.php
1 <?php
2
3 namespace Drupal\ckeditor_test\Plugin\CKEditorPlugin;
4
5 use Drupal\ckeditor\CKEditorPluginButtonsInterface;
6 use Drupal\ckeditor\CKEditorPluginContextualInterface;
7 use Drupal\ckeditor\CKEditorPluginConfigurableInterface;
8 use Drupal\Core\Form\FormStateInterface;
9 use Drupal\editor\Entity\Editor;
10
11 /**
12  * Defines a "LlamaContextualAndButton" plugin, with a contextually OR toolbar
13  * builder-enabled "llama" feature.
14  *
15  * @CKEditorPlugin(
16  *   id = "llama_contextual_and_button",
17  *   label = @Translation("Contextual Llama With Button")
18  * )
19  */
20 class LlamaContextualAndButton extends Llama implements CKEditorPluginContextualInterface, CKEditorPluginButtonsInterface, CKEditorPluginConfigurableInterface {
21
22   /**
23    * {@inheritdoc}
24    */
25   public function isEnabled(Editor $editor) {
26     // Automatically enable this plugin if the Strike button is enabled.
27     $settings = $editor->getSettings();
28     foreach ($settings['toolbar']['rows'] as $row) {
29       foreach ($row as $group) {
30         if (in_array('Strike', $group['items'])) {
31           return TRUE;
32         }
33       }
34     }
35     return FALSE;
36   }
37
38   /**
39    * {@inheritdoc}
40    */
41   public function getButtons() {
42     return [
43       'Llama' => [
44         'label' => t('Insert Llama'),
45       ],
46     ];
47   }
48
49   /**
50    * {@inheritdoc}
51    */
52   public function getFile() {
53     return drupal_get_path('module', 'ckeditor_test') . '/js/llama_contextual_and_button.js';
54   }
55
56   /**
57    * {@inheritdoc}
58    */
59   public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
60     // Defaults.
61     $config = ['ultra_llama_mode' => FALSE];
62     $settings = $editor->getSettings();
63     if (isset($settings['plugins']['llama_contextual_and_button'])) {
64       $config = $settings['plugins']['llama_contextual_and_button'];
65     }
66
67     $form['ultra_llama_mode'] = [
68       '#title' => t('Ultra llama mode'),
69       '#type' => 'checkbox',
70       '#default_value' => $config['ultra_llama_mode'],
71     ];
72
73     return $form;
74   }
75
76 }