c26bf909decf19961f9d62f4b1d0b72f53980b04
[yaffs-website] / web / core / modules / quickedit / tests / modules / src / Plugin / InPlaceEditor / WysiwygEditor.php
1 <?php
2
3 namespace Drupal\quickedit_test\Plugin\InPlaceEditor;
4
5 use Drupal\Core\Field\FieldItemListInterface;
6 use Drupal\quickedit\Plugin\InPlaceEditorBase;
7
8 /**
9  * Defines the 'wysiwyg' in-place editor.
10  *
11  * @InPlaceEditor(
12  *   id = "wysiwyg",
13  * )
14  */
15 class WysiwygEditor extends InPlaceEditorBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   public function isCompatible(FieldItemListInterface $items) {
21     $field_definition = $items->getFieldDefinition();
22
23     // This editor is incompatible with multivalued fields.
24     if ($field_definition->getFieldStorageDefinition()->getCardinality() != 1) {
25       return FALSE;
26     }
27     // This editor is compatible with formatted ("rich") text fields; but only
28     // if there is a currently active text format and that text format is the
29     // 'full_html' text format.
30     return $items[0]->format === 'full_html';
31   }
32
33   /**
34    * {@inheritdoc}
35    */
36   public function getMetadata(FieldItemListInterface $items) {
37     $metadata['format'] = $items[0]->format;
38     return $metadata;
39   }
40
41   /**
42    * {@inheritdoc}
43    */
44   public function getAttachments() {
45     return [
46       'library' => [
47         'quickedit_test/not-existing-wysiwyg',
48       ],
49     ];
50   }
51
52 }