function LoopExpression::checkIntegrity

Overrides ExpressionContainerBase::checkIntegrity

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\RulesExpression

Code

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 = $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;
}