abstract class ConditionExpressionContainer in Rules 8.3
Container for conditions.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\rules\Engine\ExpressionBase implements ExpressionInterface
- class \Drupal\rules\Engine\ExpressionContainerBase implements ExpressionContainerInterface
- class \Drupal\rules\Engine\ConditionExpressionContainer implements ContainerFactoryPluginInterface, ConditionExpressionContainerInterface
- class \Drupal\rules\Engine\ExpressionContainerBase implements ExpressionContainerInterface
- class \Drupal\rules\Engine\ExpressionBase implements ExpressionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of ConditionExpressionContainer
3 files declare their use of ConditionExpressionContainer
- AndExpression.php in src/
Plugin/ RulesExpression/ AndExpression.php - OrExpression.php in src/
Plugin/ RulesExpression/ OrExpression.php - RulesConditionContainerTest.php in tests/
src/ Unit/ RulesConditionContainerTest.php
File
- src/
Engine/ ConditionExpressionContainer.php, line 14
Namespace
Drupal\rules\EngineView source
abstract class ConditionExpressionContainer extends ExpressionContainerBase implements ConditionExpressionContainerInterface, ContainerFactoryPluginInterface {
/**
* List of conditions that are evaluated.
*
* @var \Drupal\rules\Engine\ConditionExpressionInterface[]
*/
protected $conditions = [];
/**
* Constructs a new class instance.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param array $plugin_definition
* The plugin implementation definition.
* @param \Drupal\rules\Engine\ExpressionManagerInterface $expression_manager
* The rules expression plugin manager.
* @param \Drupal\Core\Logger\LoggerChannelInterface $logger
* The Rules debug logger channel.
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, ExpressionManagerInterface $expression_manager, LoggerChannelInterface $logger) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->expressionManager = $expression_manager;
$this->rulesDebugLogger = $logger;
$configuration += [
'conditions' => [],
];
foreach ($configuration['conditions'] as $condition_config) {
$condition = $this->expressionManager
->createInstance($condition_config['id'], $condition_config);
$this->conditions[] = $condition;
}
}
/**
* {@inheritdoc}
*/
public function addExpressionObject(ExpressionInterface $expression) {
if (!$expression instanceof ConditionExpressionInterface) {
throw new InvalidExpressionException('Only condition expressions can be added to a condition container.');
}
$uuid = $expression
->getUuid();
if ($this
->getExpression($uuid)) {
throw new InvalidExpressionException("A condition with UUID {$uuid} already exists in the container.");
}
$this->conditions[] = $expression;
return $this;
}
/**
* {@inheritdoc}
*/
public function addCondition($condition_id, ContextConfig $config = NULL) {
return $this
->addExpressionObject($this->expressionManager
->createCondition($condition_id)
->setConfiguration($config ? $config
->toArray() : []));
}
/**
* {@inheritdoc}
*/
public function executeWithState(ExecutionStateInterface $rules_state) {
$result = $this
->evaluate($rules_state);
return $this
->isNegated() ? !$result : $result;
}
/**
* Returns the final result after executing the conditions.
*/
public abstract function evaluate(ExecutionStateInterface $rules_state);
/**
* {@inheritdoc}
*/
public function negate($negate = TRUE) {
$this->configuration['negate'] = $negate;
return $this;
}
/**
* {@inheritdoc}
*/
public function isNegated() {
return !empty($this->configuration['negate']);
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
$configuration = parent::getConfiguration();
// We need to update the configuration in case conditions have been added or
// changed.
$configuration['conditions'] = [];
// Use the iterator, which sorts the conditions by weight.
foreach ($this as $condition) {
$configuration['conditions'][] = $condition
->getConfiguration();
}
return $configuration;
}
/**
* {@inheritdoc}
*/
public function getIterator() {
$iterator = new \ArrayIterator($this->conditions);
$iterator
->uasort([
ExpressionContainerBase::class,
'sortByWeightProperty',
]);
return $iterator;
}
/**
* PHP magic __clone function.
*/
public function __clone() {
// Implement a deep clone.
foreach ($this->conditions as &$condition) {
$condition = clone $condition;
}
}
/**
* {@inheritdoc}
*/
public function getExpression($uuid) {
foreach ($this->conditions as $condition) {
if ($condition
->getUuid() === $uuid) {
return $condition;
}
if ($condition instanceof ExpressionContainerInterface) {
$nested_condition = $condition
->getExpression($uuid);
if ($nested_condition) {
return $nested_condition;
}
}
}
return FALSE;
}
/**
* {@inheritdoc}
*/
public function deleteExpression($uuid) {
foreach ($this->conditions as $index => $condition) {
if ($condition
->getUuid() === $uuid) {
unset($this->conditions[$index]);
return TRUE;
}
if ($condition instanceof ExpressionContainerInterface && $condition
->deleteExpression($uuid)) {
return TRUE;
}
}
return FALSE;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConditionExpressionContainer:: |
protected | property | List of conditions that are evaluated. | |
ConditionExpressionContainer:: |
public | function |
Creates a condition expression and adds it to the container. Overrides ConditionExpressionContainerInterface:: |
|
ConditionExpressionContainer:: |
public | function |
Adds an expression object. Overrides ExpressionContainerInterface:: |
|
ConditionExpressionContainer:: |
public | function |
Deletes an expression identified by the specified UUID in the container. Overrides ExpressionContainerInterface:: |
|
ConditionExpressionContainer:: |
abstract public | function | Returns the final result after executing the conditions. | 3 |
ConditionExpressionContainer:: |
public | function |
Execute the expression with a given Rules state. Overrides ExpressionInterface:: |
|
ConditionExpressionContainer:: |
public | function |
Gets this plugin's configuration. Overrides ExpressionBase:: |
|
ConditionExpressionContainer:: |
public | function |
Looks up the expression by UUID in this container. Overrides ExpressionContainerInterface:: |
|
ConditionExpressionContainer:: |
public | function | ||
ConditionExpressionContainer:: |
public | function |
Determines whether condition result will be negated. Overrides ConditionExpressionInterface:: |
|
ConditionExpressionContainer:: |
public | function |
Negates the result after evaluating this condition. Overrides ConditionExpressionInterface:: |
|
ConditionExpressionContainer:: |
public | function | PHP magic __clone function. | |
ConditionExpressionContainer:: |
public | function |
Constructs a new class instance. Overrides ExpressionBase:: |
|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
ExpressionBase:: |
protected | property | The config entity this expression is associated with, if any. | |
ExpressionBase:: |
protected | property |
The plugin configuration. Overrides PluginBase:: |
|
ExpressionBase:: |
protected | property | The root expression if this object is nested. | |
ExpressionBase:: |
protected | property | The UUID of this expression. | |
ExpressionBase:: |
protected | property | The weight (list order) of this expression. | |
ExpressionBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
ExpressionBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
2 |
ExpressionBase:: |
public | function |
Executes a rules expression. Overrides ExecutableInterface:: |
|
ExpressionBase:: |
public | function |
Returns the form handling class for this expression. Overrides ExpressionInterface:: |
2 |
ExpressionBase:: |
public | function |
The label of this expression element that can be shown in the UI. Overrides ExpressionInterface:: |
2 |
ExpressionBase:: |
public | function |
Returns the root expression if this expression is nested. Overrides ExpressionInterface:: |
|
ExpressionBase:: |
public | function |
Returns the UUID of this expression if it is nested in another expression. Overrides ExpressionInterface:: |
|
ExpressionBase:: |
public | function |
Returns the list order of this expression. Overrides ExpressionInterface:: |
|
ExpressionBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
2 |
ExpressionBase:: |
public | function |
Set the root expression for this expression if it is nested. Overrides ExpressionInterface:: |
|
ExpressionBase:: |
public | function |
Sets the UUID of this expression in an expression tree. Overrides ExpressionInterface:: |
|
ExpressionBase:: |
public | function |
Sets the list order of this expression in an expression tree. Overrides ExpressionInterface:: |
|
ExpressionContainerBase:: |
protected | property | The expression manager. | |
ExpressionContainerBase:: |
protected | property | The rules debug logger channel. | |
ExpressionContainerBase:: |
public | function |
Creates and adds an expression. Overrides ExpressionContainerInterface:: |
|
ExpressionContainerBase:: |
abstract protected | function | Determines whether child-expressions are allowed to assert metadata. | 4 |
ExpressionContainerBase:: |
public | function |
Verifies that this expression is configured correctly. Overrides ExpressionInterface:: |
1 |
ExpressionContainerBase:: |
public static | function | ||
ExpressionContainerBase:: |
public | function |
Prepares the execution metadata state by adding metadata to it. Overrides ExpressionInterface:: |
|
ExpressionContainerBase:: |
protected | function | Prepares execution metadata state after traversing through children. | 1 |
ExpressionContainerBase:: |
protected | function | Prepares execution metadata state before traversing through children. | 1 |
ExpressionContainerBase:: |
public static | function | Sorts an array of expressions by 'weight' property. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |