-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathExpressionBase.php
More file actions
193 lines (167 loc) · 3.71 KB
/
ExpressionBase.php
File metadata and controls
193 lines (167 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
namespace Drupal\rules\Engine;
use Drupal\Core\Plugin\PluginBase;
/**
* Base class for rules expressions.
*/
abstract class ExpressionBase extends PluginBase implements ExpressionInterface {
/**
* The plugin configuration.
*
* @var array
*/
protected $configuration;
/**
* The root expression if this object is nested.
*
* @var \Drupal\rules\Engine\ExpressionInterface
*/
protected $root;
/**
* The config entity this expression is associated with, if any.
*
* @var string
*/
protected $configEntityId;
/**
* The UUID of this expression.
*
* @var string
*/
protected $uuid;
/**
* The weight of this expression.
*
* @var integer
*/
protected $weight;
/**
* Constructor.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->setConfiguration($configuration);
}
/**
* Executes a rules expression.
*/
public function execute() {
// If there is no state given, we have to assume no required context.
$state = ExecutionState::create();
$result = $this->executeWithState($state);
// Save specifically registered variables in the end after execution.
$state->autoSave();
return $result;
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
return [
'id' => $this->getPluginId(),
'uuid' => $this->uuid,
'weight' => $this->weight,
] + $this->configuration;
}
/**
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
$this->configuration = $configuration + $this->defaultConfiguration();
if (isset($configuration['uuid'])) {
$this->uuid = $configuration['uuid'];
}
if (isset($configuration['weight'])) {
$this->weight = $configuration['weight'];
}
else {
$this->weight = 0;
}
return $this;
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [];
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
return [];
}
/**
* {@inheritdoc}
*/
public function getFormHandler() {
if (isset($this->pluginDefinition['form_class'])) {
$class_name = $this->pluginDefinition['form_class'];
return new $class_name($this);
}
}
/**
* {@inheritdoc}
*/
public function getRoot() {
if (isset($this->root)) {
// @todo: This seems to be the parent, not root.
return $this->root->getRoot();
}
return $this;
}
/**
* {@inheritdoc}
*/
public function setRoot(ExpressionInterface $root) {
$this->root = $root;
}
/**
* {@inheritdoc}
*/
public function getLabel() {
return $this->pluginDefinition['label'];
}
/**
* {@inheritdoc}
*/
public function getUuid() {
return $this->uuid;
}
/**
* {@inheritdoc}
*/
public function setUuid($uuid) {
$this->uuid = $uuid;
}
/**
* {@inheritdoc}
*/
public function getWeight() {
return $this->weight;
}
/**
* {@inheritdoc}
*/
public function setWeight($weight) {
$this->weight = $weight;
}
/**
* {@inheritdoc}
*/
public function expressionSortHelper(ExpressionInterface $a, ExpressionInterface $b) {
$a_weight = $a->getWeight();
$b_weight = $b->getWeight();
if ($a_weight == $b_weight) {
return 0;
}
return ($a_weight < $b_weight) ? -1 : 1;
}
}