Paragraphs Editor
FieldValueWrapper.php
Go to the documentation of this file.
1 <?php
2 
4 
7 
8 /**
9  * Wraps a paragraphs editor field.
10  */
12 
13  /**
14  * The paragraph containing the field text.
15  *
16  * @var \Drupal\paragraphs\ParagraphInterface
17  */
18  protected $textEntity;
19 
20  /**
21  * A list of paragraphs referenced in the text entity.
22  *
23  * @var \Drupal\paragraphs\ParagraphInterface[]
24  */
26 
27  /**
28  * The field settings.
29  *
30  * @var array
31  */
32  protected $settings;
33 
34  /**
35  * Creates a paragraphs editor field wrapper.
36  *
37  * @param \Drupal\Core\Field\FieldConfigInterface $field_definition
38  * The field definition to extract the field settings from.
39  * @param \Drupal\paragraphs\ParagraphInterface $text_entity
40  * The paragraph containing the field text.
41  * @param \Drupal\paragraphs\ParagraphInterface[] $referenced_entities
42  * A list of paragraphs referenced in the text entity.
43  */
44  public function __construct(FieldConfigInterface $field_definition, ParagraphInterface $text_entity, array $referenced_entities) {
45  $this->textEntity = $text_entity;
46  $this->setReferencedEntities($referenced_entities);
47  $this->settings = $field_definition->getThirdPartySettings('paragraphs_editor');
48  }
49 
50  /**
51  * {@inheritdoc}
52  */
53  public function getTextEntity() {
54  return $this->textEntity;
55  }
56 
57  /**
58  * {@inheritdoc}
59  */
60  public function getMarkup() {
61  return $this->textEntity->{$this->settings['text_field']}->value;
62  }
63 
64  /**
65  * {@inheritdoc}
66  */
67  public function getFormat() {
68  return $this->textEntity->{$this->settings['text_field']}->format;
69  }
70 
71  /**
72  * {@inheritdoc}
73  */
74  public function getEntities() {
75  return array_merge([$this->getTextEntity()], array_values($this->getReferencedEntities()));
76  }
77 
78  /**
79  * {@inheritdoc}
80  */
81  public function getReferencedEntities() {
83  }
84 
85  /**
86  * {@inheritdoc}
87  */
88  public function setMarkup($markup) {
89  $this->textEntity->{$this->settings['text_field']}->value = $markup;
90  }
91 
92  /**
93  * {@inheritdoc}
94  */
95  public function setFormat($format) {
96  $this->textEntity->{$this->settings['text_field']}->format = $format;
97  }
98 
99  /**
100  * {@inheritdoc}
101  */
102  public function setReferencedEntities(array $entities) {
103  $this->referencedEntities = $entities;
104  }
105 
106  /**
107  * {@inheritdoc}
108  */
109  public function addReferencedEntity(ParagraphInterface $entity) {
110  $this->referencedEntities[$entity->uuid()] = $entity;
111  }
112 
113 }
__construct(FieldConfigInterface $field_definition, ParagraphInterface $text_entity, array $referenced_entities)