Paragraphs Editor
ParagraphsEditorDecorator.php
Go to the documentation of this file.
1 <?php
2 
4 
12 
13 /**
14  * A DOM processor plugin for decorating widgets with a context hint.
15  *
16  * @DomProcessorDataProcessor(
17  * id = "paragraphs_editor_decorator",
18  * label = "Paragraphs Editor Decorator"
19  * )
20  */
21 class ParagraphsEditorDecorator implements DataProcessorInterface, ContainerFactoryPluginInterface {
23 
24  /**
25  * Creates a widget decorator plugin.
26  *
27  * @param \Drupal\paragraphs_editor\EditorFieldValue\FieldValueManagerInterface $field_value_manager
28  * The field value manager service to initialize the element trait.
29  */
30  public function __construct(FieldValueManagerInterface $field_value_manager) {
31  $this->initializeParagraphsEditorElementTrait($field_value_manager);
32  }
33 
34  /**
35  * {@inheritdoc}
36  */
37  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
38  return new static(
39  $container->get('paragraphs_editor.field_value.manager')
40  );
41  }
42 
43  /**
44  * {@inheritdoc}
45  */
46  public function process(SemanticDataInterface $data, DomProcessorResultInterface $result) {
47  if ($data->is($this->getSelector('widget'))) {
48  $this->setAttribute($data->node(), 'widget', '<context>', $data->get('context_id'));
49  }
50  return $result;
51  }
52 
53 }
setAttribute(\DOMNode $node, $element_name, $attribute_name, $value)
static create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition)
process(SemanticDataInterface $data, DomProcessorResultInterface $result)
initializeParagraphsEditorElementTrait(FieldValueManagerInterface $field_value_manager)