public function LoopExpression::checkIntegrity in Rules 8.3
Verifies that this expression is configured correctly.
Example: All configured data selectors must be valid.
Note that for checking integrity the execution metadata state must be passed prepared as achieved by ::prepareExecutionMetadataState() and the expression must apply all metadata state preparations during its integrity check as it does in ::prepareExecutionMetadataState(). This allows for efficient integrity checks of expression trees; e.g. see \Drupal\rules\Engine\ActionExpressionContainer::checkIntegrity().
Parameters
\Drupal\rules\Context\ExecutionMetadataStateInterface $metadata_state: The execution metadata state, prepared until right before this expression.
bool $apply_assertions: (optional) Whether to apply metadata assertions while preparing the execution metadata state. Defaults to TRUE.
Return value
\Drupal\rules\Engine\IntegrityViolationList A list object containing \Drupal\rules\Engine\IntegrityViolation objects.
Overrides ExpressionContainerBase::checkIntegrity
See also
::prepareExecutionMetadataState()
File
- src/
Plugin/ RulesExpression/ LoopExpression.php, line 59
Class
- LoopExpression
- Holds a set of actions that are executed over the iteration of a list.
Namespace
Drupal\rules\Plugin\RulesExpressionCode
public function checkIntegrity(ExecutionMetadataStateInterface $metadata_state, $apply_assertions = TRUE) {
$violation_list = new IntegrityViolationList();
if (empty($this->configuration['list'])) {
$violation_list
->addViolationWithMessage($this
->t('List variable is missing.'));
return $violation_list;
}
try {
$list_definition = $metadata_state
->fetchDefinitionByPropertyPath($this->configuration['list']);
} catch (IntegrityException $e) {
$violation_list
->addViolationWithMessage($this
->t('List variable %list does not exist. @message', [
'%list' => $this->configuration['list'],
'@message' => $e
->getMessage(),
]));
return $violation_list;
}
$list_item_name = isset($this->configuration['list_item']) ? $this->configuration['list_item'] : 'list_item';
if ($metadata_state
->hasDataDefinition($list_item_name)) {
$violation_list
->addViolationWithMessage($this
->t('List item name %name conflicts with an existing variable.', [
'%name' => $list_item_name,
]));
return $violation_list;
}
if (!$list_definition instanceof ListDataDefinitionInterface) {
$violation_list
->addViolationWithMessage($this
->t('The data type of list variable %list is not a list.', [
'%list' => $this->configuration['list'],
]));
return $violation_list;
}
// So far all ok, so continue with checking integrity in contained actions.
// The parent implementation will take care of invoking pre/post traversal
// metadata state preparations.
$violation_list = parent::checkIntegrity($metadata_state, $apply_assertions);
return $violation_list;
}