Paragraphs Editor
Main Page
Namespaces
Classes
Files
File List
WidgetBinderDataCompilerState.php
Go to the documentation of this file.
1
<?php
2
3
namespace
Drupal\paragraphs_editor\WidgetBinder
;
4
5
use
Drupal\paragraphs_editor\EditBuffer\EditBufferItemInterface
;
6
use
Drupal\paragraphs_editor\EditorCommand\CommandContextInterface
;
7
8
/**
9
* Holds the state of the widget binder data compiler.
10
*
11
* Since each generator is defined as a service, state information cannot be
12
* safely kept as a property of the generator itself. To allow generators to
13
* track and aggregate progress, we introduce a state object.
14
*/
15
class
WidgetBinderDataCompilerState
{
16
17
/**
18
* Contains the state data that will be destroyed at the end of compilation.
19
*
20
* @var array
21
*/
22
protected
$temporaryData
= [];
23
24
/**
25
* Contains the current compiled data.
26
*
27
* @var \Drupal\paragraphs_editor\WidgetBinder\WidgetBinderData
28
*/
29
protected
$compiledData
;
30
31
/**
32
* Contains the list of active generator service objects.
33
*
34
* @var \Drupal\paragraphs_editor\WidgetBinder\GeneratorInterface[]
35
*/
36
protected
$generators
;
37
38
/**
39
* The context containing the edit buffer item currently being compiled.
40
*
41
* @var \Drupal\paragraphs_editor\EditorCommand\CommandContextInterface
42
*/
43
protected
$itemContext
;
44
45
/**
46
* The edit buffer item currently being compiled.
47
*
48
* @var \Drupal\paragraphs_editor\EditBuffer\EditBufferItemInterface
49
*/
50
protected
$item
;
51
52
/**
53
* Creates a WidgetBinderDataCompilerState object.
54
*
55
* @param \Drupal\paragraphs_editor\WidgetBinder\GeneratorInterface[] $generators
56
* A key value map where keys are generator ids and values are generator
57
* instances that are active for the current compiler session.
58
* @param \Drupal\paragraphs_editor\WidgetBinder\WidgetBinderData $data
59
* The compiled data containing the models that will be delivered to the
60
* client.
61
* @param \Drupal\paragraphs_editor\EditorCommand\CommandContextInterface $context
62
* The context containing the edit buffer item being compiled.
63
* @param \Drupal\paragraphs_editor\EditBuffer\EditBufferItemInterface $item
64
* The edit buffer item being compiled.
65
*/
66
public
function
__construct
(array
$generators
,
WidgetBinderData
$data,
CommandContextInterface
$context,
EditBufferItemInterface
$item
) {
67
$this->compiledData = $data;
68
$this->generators =
$generators
;
69
$this->itemContext = $context;
70
$this->item =
$item
;
71
}
72
73
/**
74
* Getter for the compiled widget binder data.
75
*
76
* @return \Drupal\paragraphs_editor\WidgetBinder\WidgetBinderData
77
* The widget binder data to be delivered to the client.
78
*/
79
public
function
getCompiledData
() {
80
return
$this->compiledData
;
81
}
82
83
/**
84
* Getter for the context containing the item being edited.
85
*
86
* @return \Drupal\paragraphs_editor\EditorCommand\CommandContextInterface
87
* The context containing the item being edited.
88
*/
89
public
function
getItemContext
() {
90
return
$this->itemContext
;
91
}
92
93
/**
94
* Getter for the edit buffer item being compiled.
95
*
96
* @return \Drupal\paragraphs_editor\EditBuffer\EditBufferItemInterface
97
* The edit buffer item being compiled.
98
*/
99
public
function
getItem
() {
100
return
$this->item
;
101
}
102
103
/**
104
* Gets a generator by its generator id.
105
*
106
* @return \Drupal\paragraphs_editor\WidgetBinder\GeneratorInterface|null
107
* The generator service implementation assocaited with a generator id, or
108
* NULL if no such generator exists.
109
*/
110
public
function
getGenerator
($id) {
111
return
!empty($this->generators[$id]) ? $this->generators[$id] : NULL;
112
}
113
114
/**
115
* Gets a key from the temporary state store.
116
*
117
* @param string|null $key
118
* A key entry to get the value for, or NULL to return an array of all
119
* values.
120
*
121
* @return mixed
122
* The value associated with the specified key, or an array of all key value
123
* pairs if NULL was passed.
124
*/
125
public
function
get
($key = NULL) {
126
if
(isset($key)) {
127
return
isset($this->temporaryData[$key]) ? $this->temporaryData[$key] : NULL;
128
}
129
else
{
130
return
$this->temporaryData
;
131
}
132
}
133
134
/**
135
* Sets a temporary state value.
136
*
137
* @param string $key
138
* The key of the temporary value to set.
139
* @param mixed $value
140
* The value to store in the temporary state cache.
141
*/
142
public
function
set
($key, $value) {
143
$this->temporaryData[$key] = $value;
144
}
145
146
}
EditBufferItemInterface
Drupal\paragraphs_editor\WidgetBinder\WidgetBinderDataCompilerState\$itemContext
$itemContext
Definition:
WidgetBinderDataCompilerState.php:43
Drupal\paragraphs_editor\EditorCommand\CommandContextInterface
Definition:
CommandContextInterface.php:18
CommandContextInterface
Drupal\paragraphs_editor\WidgetBinder\WidgetBinderDataCompilerState\$temporaryData
$temporaryData
Definition:
WidgetBinderDataCompilerState.php:22
Drupal\paragraphs_editor\WidgetBinder\WidgetBinderDataCompilerState\getItemContext
getItemContext()
Definition:
WidgetBinderDataCompilerState.php:89
Drupal\paragraphs_editor\WidgetBinder
Definition:
EditableField.php:3
Drupal\paragraphs_editor\WidgetBinder\WidgetBinderDataCompilerState
Definition:
WidgetBinderDataCompilerState.php:15
Drupal\paragraphs_editor\WidgetBinder\WidgetBinderDataCompilerState\$item
$item
Definition:
WidgetBinderDataCompilerState.php:50
Drupal\paragraphs_editor\WidgetBinder\WidgetBinderDataCompilerState\getItem
getItem()
Definition:
WidgetBinderDataCompilerState.php:99
Drupal\paragraphs_editor\WidgetBinder\WidgetBinderDataCompilerState\getCompiledData
getCompiledData()
Definition:
WidgetBinderDataCompilerState.php:79
Drupal\paragraphs_editor\WidgetBinder\WidgetBinderDataCompilerState\$compiledData
$compiledData
Definition:
WidgetBinderDataCompilerState.php:29
Drupal\paragraphs_editor\WidgetBinder\WidgetBinderDataCompilerState\$generators
$generators
Definition:
WidgetBinderDataCompilerState.php:36
Drupal\paragraphs_editor\EditBuffer\EditBufferItemInterface
Definition:
EditBufferItemInterface.php:15
Drupal\paragraphs_editor\WidgetBinder\WidgetBinderDataCompilerState\__construct
__construct(array $generators, WidgetBinderData $data, CommandContextInterface $context, EditBufferItemInterface $item)
Definition:
WidgetBinderDataCompilerState.php:66
Drupal\paragraphs_editor\WidgetBinder\WidgetBinderDataCompilerState\getGenerator
getGenerator($id)
Definition:
WidgetBinderDataCompilerState.php:110
Drupal\paragraphs_editor\WidgetBinder\WidgetBinderData
Definition:
WidgetBinderData.php:13
src
WidgetBinder
WidgetBinderDataCompilerState.php
Generated by
1.8.11