class ActionExpressionContainer
Container for actions.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
- class \Drupal\rules\Engine\ExpressionBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\rules\Engine\ExpressionInterface
- class \Drupal\rules\Engine\ExpressionContainerBase extends \Drupal\rules\Engine\ExpressionBase implements \Drupal\rules\Engine\ExpressionContainerInterface
- class \Drupal\rules\Engine\ActionExpressionContainer extends \Drupal\rules\Engine\ExpressionContainerBase implements \Drupal\rules\Engine\ActionExpressionContainerInterface, \Drupal\Core\Plugin\ContainerFactoryPluginInterface
- class \Drupal\rules\Engine\ExpressionContainerBase extends \Drupal\rules\Engine\ExpressionBase implements \Drupal\rules\Engine\ExpressionContainerInterface
- class \Drupal\rules\Engine\ExpressionBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\rules\Engine\ExpressionInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
Expanded class hierarchy of ActionExpressionContainer
2 files declare their use of ActionExpressionContainer
- ActionSetExpression.php in src/
Plugin/ RulesExpression/ ActionSetExpression.php - LoopExpression.php in src/
Plugin/ RulesExpression/ LoopExpression.php
File
-
src/
Engine/ ActionExpressionContainer.php, line 13
Namespace
Drupal\rules\EngineView source
abstract class ActionExpressionContainer extends ExpressionContainerBase implements ActionExpressionContainerInterface, ContainerFactoryPluginInterface {
/**
* List of actions that will be executed.
*
* @var \Drupal\rules\Engine\ActionExpressionInterface[]
*/
protected $actions = [];
/**
* 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 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 += [
'actions' => [],
];
foreach ($configuration['actions'] as $action_config) {
$action = $expression_manager->createInstance($action_config['id'], $action_config);
$this->actions[] = $action;
}
}
/**
* {@inheritdoc}
*/
public function addExpressionObject(ExpressionInterface $expression) {
if (!$expression instanceof ActionExpressionInterface) {
throw new InvalidExpressionException('Only action expressions can be added to an action container.');
}
$uuid = $expression->getUuid();
if ($this->getExpression($uuid)) {
throw new InvalidExpressionException("An action with UUID {$uuid} already exists in the container.");
}
$this->actions[] = $expression;
return $this;
}
/**
* {@inheritdoc}
*/
public function addAction($action_id, ContextConfig $config = NULL) {
return $this->addExpressionObject($this->expressionManager
->createAction($action_id)
->setConfiguration($config ? $config->toArray() : []));
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
$configuration = parent::getConfiguration();
// We need to update the configuration in case actions have been added or
// changed.
$configuration['actions'] = [];
// Use the iterator, which sorts the actions by weight.
foreach ($this as $action) {
$configuration['actions'][] = $action->getConfiguration();
}
return $configuration;
}
/**
* {@inheritdoc}
*/
public function getIterator() : \Traversable {
$iterator = new \ArrayIterator($this->actions);
$iterator->uasort([
ExpressionContainerBase::class,
'sortByWeightProperty',
]);
return $iterator;
}
/**
* PHP magic __clone function.
*/
public function __clone() {
// Implement a deep clone.
foreach ($this->actions as &$action) {
$action = clone $action;
}
}
/**
* {@inheritdoc}
*/
public function getExpression($uuid) {
foreach ($this->actions as $action) {
if ($action->getUuid() === $uuid) {
return $action;
}
if ($action instanceof ExpressionContainerInterface) {
$nested_action = $action->getExpression($uuid);
if ($nested_action) {
return $nested_action;
}
}
}
return FALSE;
}
/**
* {@inheritdoc}
*/
public function deleteExpression($uuid) {
foreach ($this->actions as $index => $action) {
if ($action->getUuid() === $uuid) {
unset($this->actions[$index]);
return TRUE;
}
if ($action instanceof ExpressionContainerInterface && $action->deleteExpression($uuid)) {
return TRUE;
}
}
return FALSE;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
ActionExpressionContainer::$actions | protected | property | List of actions that will be executed. | ||
ActionExpressionContainer::addAction | public | function | Creates an action expression and adds it to the container. | Overrides ActionExpressionContainerInterface::addAction | |
ActionExpressionContainer::addExpressionObject | public | function | Adds an expression object. | Overrides ExpressionContainerInterface::addExpressionObject | |
ActionExpressionContainer::deleteExpression | public | function | Deletes an expression identified by the specified UUID in the container. | Overrides ExpressionContainerInterface::deleteExpression | |
ActionExpressionContainer::getConfiguration | public | function | Gets this plugin's configuration. | Overrides ExpressionBase::getConfiguration | |
ActionExpressionContainer::getExpression | public | function | Looks up the expression by UUID in this container. | Overrides ExpressionContainerInterface::getExpression | |
ActionExpressionContainer::getIterator | public | function | Returns an iterator for expressions in this container. | Overrides ExpressionContainerInterface::getIterator | |
ActionExpressionContainer::__clone | public | function | PHP magic __clone function. | ||
ActionExpressionContainer::__construct | public | function | Constructor. | Overrides ExpressionBase::__construct | |
ExpressionBase::$configEntityId | protected | property | The config entity this expression is associated with, if any. | ||
ExpressionBase::$configuration | protected | property | The plugin configuration. | ||
ExpressionBase::$root | protected | property | The root expression if this object is nested. | ||
ExpressionBase::$uuid | protected | property | The UUID of this expression. | ||
ExpressionBase::$weight | protected | property | The weight (list order) of this expression. | ||
ExpressionBase::calculateDependencies | public | function | Calculates dependencies for the configured plugin. | Overrides DependentPluginInterface::calculateDependencies | |
ExpressionBase::defaultConfiguration | public | function | Gets default configuration for this plugin. | Overrides ConfigurableInterface::defaultConfiguration | 2 |
ExpressionBase::execute | public | function | Executes a rules expression. | Overrides ExecutableInterface::execute | |
ExpressionBase::getFormHandler | public | function | Returns the form handling class for this expression. | Overrides ExpressionInterface::getFormHandler | 2 |
ExpressionBase::getLabel | public | function | The label of this expression element that can be shown in the UI. | Overrides ExpressionInterface::getLabel | 2 |
ExpressionBase::getRoot | public | function | Returns the root expression if this expression is nested. | Overrides ExpressionInterface::getRoot | |
ExpressionBase::getUuid | public | function | Returns the UUID of this expression if it is nested in another expression. | Overrides ExpressionInterface::getUuid | |
ExpressionBase::getWeight | public | function | Returns the list order of this expression. | Overrides ExpressionInterface::getWeight | |
ExpressionBase::setConfiguration | public | function | Sets the configuration for this plugin instance. | Overrides ConfigurableInterface::setConfiguration | 2 |
ExpressionBase::setRoot | public | function | Set the root expression for this expression if it is nested. | Overrides ExpressionInterface::setRoot | |
ExpressionBase::setUuid | public | function | Sets the UUID of this expression in an expression tree. | Overrides ExpressionInterface::setUuid | |
ExpressionBase::setWeight | public | function | Sets the list order of this expression in an expression tree. | Overrides ExpressionInterface::setWeight | |
ExpressionContainerBase::$expressionManager | protected | property | The expression manager. | ||
ExpressionContainerBase::$rulesDebugLogger | protected | property | The rules debug logger channel. | ||
ExpressionContainerBase::addExpression | public | function | Creates and adds an expression. | Overrides ExpressionContainerInterface::addExpression | |
ExpressionContainerBase::allowsMetadataAssertions | abstract protected | function | Determines whether child-expressions are allowed to assert metadata. | 4 | |
ExpressionContainerBase::checkIntegrity | public | function | Verifies that this expression is configured correctly. | Overrides ExpressionInterface::checkIntegrity | 1 |
ExpressionContainerBase::create | public static | function | |||
ExpressionContainerBase::prepareExecutionMetadataState | public | function | Prepares the execution metadata state by adding metadata to it. | Overrides ExpressionInterface::prepareExecutionMetadataState | |
ExpressionContainerBase::prepareExecutionMetadataStateAfterTraversal | protected | function | Prepares execution metadata state after traversing through children. | 1 | |
ExpressionContainerBase::prepareExecutionMetadataStateBeforeTraversal | protected | function | Prepares execution metadata state before traversing through children. | 1 | |
ExpressionContainerBase::sortByWeightProperty | public static | function | Sorts an array of expressions by 'weight' property. | ||
ExpressionInterface::executeWithState | public | function | Execute the expression with a given Rules state. | 6 | |
PluginInspectionInterface::getPluginDefinition | public | function | Gets the definition of the plugin implementation. | 6 | |
PluginInspectionInterface::getPluginId | public | function | Gets the plugin_id of the plugin instance. | 2 |