ExpressionBase.php in Rules 8.3
File
src/Engine/ExpressionBase.php
View source
<?php
namespace Drupal\rules\Engine;
use Drupal\Core\Plugin\PluginBase;
use Drupal\rules\Context\ExecutionState;
abstract class ExpressionBase extends PluginBase implements ExpressionInterface {
protected $configuration;
protected $root;
protected $configEntityId;
protected $uuid;
protected $weight = 0;
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this
->setConfiguration($configuration);
}
public function execute() {
$state = ExecutionState::create();
$result = $this
->executeWithState($state);
$state
->autoSave();
return $result;
}
public function getConfiguration() {
return [
'id' => $this
->getPluginId(),
'uuid' => $this->uuid,
'weight' => $this->weight,
] + $this->configuration;
}
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'];
}
return $this;
}
public function defaultConfiguration() {
return [];
}
public function calculateDependencies() {
return [];
}
public function getFormHandler() {
if (isset($this->pluginDefinition['form_class'])) {
$class_name = $this->pluginDefinition['form_class'];
return new $class_name($this);
}
}
public function getRoot() {
if (isset($this->root)) {
return $this->root
->getRoot();
}
return $this;
}
public function setRoot(ExpressionInterface $root) {
$this->root = $root;
return $this;
}
public function getLabel() {
return $this->pluginDefinition['label'];
}
public function getUuid() {
return $this->uuid;
}
public function setUuid($uuid) {
$this->uuid = $uuid;
return $this;
}
public function getWeight() {
return $this->weight;
}
public function setWeight($weight) {
$this->weight = $weight;
return $this;
}
}