|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\paragraphs_editor\EditorFieldValue; |
|
4
|
|
|
|
|
5
|
|
|
use Drupal\Core\Field\FieldConfigInterface; |
|
6
|
|
|
use Drupal\paragraphs\ParagraphInterface; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Wraps a paragraphs editor field. |
|
10
|
|
|
*/ |
|
11
|
|
|
class FieldValueWrapper implements FieldValueWrapperInterface { |
|
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
|
|
|
*/ |
|
25
|
|
|
protected $referencedEntities; |
|
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
|
4 |
|
public function __construct(FieldConfigInterface $field_definition, ParagraphInterface $text_entity, array $referenced_entities) { |
|
45
|
4 |
|
$this->textEntity = $text_entity; |
|
46
|
4 |
|
$this->setReferencedEntities($referenced_entities); |
|
47
|
4 |
|
$this->settings = $field_definition->getThirdPartySettings('paragraphs_editor'); |
|
48
|
4 |
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* {@inheritdoc} |
|
52
|
|
|
*/ |
|
53
|
|
|
public function getTextEntity() { |
|
54
|
|
|
return $this->textEntity; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* {@inheritdoc} |
|
59
|
|
|
*/ |
|
60
|
4 |
|
public function getMarkup() { |
|
61
|
4 |
|
return $this->textEntity->{$this->settings['text_field']}->value; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* {@inheritdoc} |
|
66
|
|
|
*/ |
|
67
|
4 |
|
public function getFormat() { |
|
68
|
4 |
|
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
|
4 |
|
public function getReferencedEntities() { |
|
82
|
4 |
|
return $this->referencedEntities; |
|
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
|
4 |
|
public function setReferencedEntities(array $entities) { |
|
103
|
4 |
|
$this->referencedEntities = $entities; |
|
104
|
4 |
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* {@inheritdoc} |
|
108
|
|
|
*/ |
|
109
|
|
|
public function addReferencedEntity(ParagraphInterface $entity) { |
|
110
|
|
|
$this->referencedEntities[$entity->uuid()] = $entity; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
} |
|
114
|
|
|
|