/** * {@inheritdoc} */ public function checkIntegrity(ExecutionMetadataStateInterface $metadata_state, $apply_assertions = TRUE) { $violation_list = new IntegrityViolationList(); $this->prepareExecutionMetadataStateBeforeTraversal($metadata_state); $apply_assertions = $apply_assertions && $this->allowsMetadataAssertions(); foreach ($this as $child_expression) { $child_violations = $child_expression->checkIntegrity($metadata_state, $apply_assertions); $violation_list->addAll($child_violations); } $this->prepareExecutionMetadataStateAfterTraversal($metadata_state); return $violation_list; }
/** * {@inheritdoc} */ public function checkIntegrity(ExecutionMetadataStateInterface $metadata_state) { $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 (RulesIntegrityException $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) { $list_item_definition = $list_definition->getItemDefinition(); $metadata_state->setDataDefinition($list_item_name, $list_item_definition); $violation_list = parent::checkIntegrity($metadata_state); // Remove the list item variable after the loop, it is out of scope now. $metadata_state->removeDataDefinition($list_item_name); return $violation_list; } $violation_list->addViolationWithMessage($this->t('The data type of list variable %list is not a list.', ['%list' => $this->configuration['list']])); return $violation_list; }
/** * {@inheritdoc} */ public function checkIntegrity(ExecutionMetadataStateInterface $metadata_state) { $violation_list = new IntegrityViolationList(); foreach ($this->conditions as $uuid => $condition) { $condition_violations = $condition->checkIntegrity($metadata_state); foreach ($condition_violations as $violation) { $violation->setUuid($uuid); } $violation_list->addAll($condition_violations); } return $violation_list; }
/** * {@inheritdoc} */ public function checkIntegrity(ExecutionMetadataStateInterface $metadata_state, $apply_assertions = TRUE) { $violation_list = new IntegrityViolationList(); if (empty($this->configuration['action_id'])) { $violation_list->addViolationWithMessage($this->t('Action plugin ID is missing'), $this->getUuid()); return $violation_list; } if (!$this->actionManager->hasDefinition($this->configuration['action_id'])) { $violation_list->addViolationWithMessage($this->t('Action plugin %plugin_id does not exist', ['%plugin_id' => $this->configuration['action_id']]), $this->getUuid()); return $violation_list; } $action = $this->actionManager->createInstance($this->configuration['action_id']); // Prepare and refine the context before checking integrity, such that any // context definition changes are respected while checking. $this->prepareContextWithMetadata($action, $metadata_state); $result = $this->checkContextConfigIntegrity($action, $metadata_state); $this->prepareExecutionMetadataState($metadata_state, NULL, $apply_assertions); return $result; }
/** * {@inheritdoc} */ public function checkIntegrity(ExecutionMetadataStateInterface $metadata_state) { $violation_list = new IntegrityViolationList(); if (empty($this->configuration['action_id'])) { $violation_list->addViolationWithMessage($this->t('Action plugin ID is missing')); return $violation_list; } if (!$this->actionManager->hasDefinition($this->configuration['action_id'])) { $violation_list->addViolationWithMessage($this->t('Action plugin %plugin_id does not exist', ['%plugin_id' => $this->configuration['action_id']])); return $violation_list; } $action = $this->actionManager->createInstance($this->configuration['action_id']); return $this->doCheckIntegrity($action, $metadata_state); }
/** * Checks that the data type of a mapped variable matches the expectation. * * @param \Drupal\Core\Plugin\Context\ContextDefinitionInterface $context_definition * The context definition of the context on the plugin. * @param \Drupal\Core\TypedData\DataDefinitionInterface $provided * The data definition of the mapped variable to the context. * @param string $context_name * The name of the context on the plugin. * @param \Drupal\rules\Engine\IntegrityViolationList $violation_list * The list of violations where new ones will be added. */ protected function checkDataTypeCompatible(ContextDefinitionInterface $context_definition, DataDefinitionInterface $provided, $context_name, IntegrityViolationList $violation_list) { $expected_class = $context_definition->getDataDefinition()->getClass(); $provided_class = $provided->getClass(); $expected_type_problem = NULL; if (is_subclass_of($expected_class, PrimitiveInterface::class) && !is_subclass_of($provided_class, PrimitiveInterface::class)) { $expected_type_problem = $this->t('primitive'); } elseif (is_subclass_of($expected_class, ListInterface::class) && !is_subclass_of($provided_class, ListInterface::class)) { $expected_type_problem = $this->t('list'); } elseif (is_subclass_of($expected_class, ComplexDataInterface::class) && !is_subclass_of($provided_class, ComplexDataInterface::class)) { $expected_type_problem = $this->t('complex'); } if ($expected_type_problem) { $violation = new IntegrityViolation(); $violation->setMessage($this->t('Expected a @expected_type data type for context %context_name but got a @provided_type data type instead.', ['@expected_type' => $expected_type_problem, '%context_name' => $context_definition->getLabel(), '@provided_type' => $provided->getDataType()])); $violation->setContextName($context_name); $violation_list->add($violation); } }
/** * Checks that the data type of a mapped variable matches the expectation. * * @param \Drupal\Core\Plugin\Context\ContextDefinitionInterface $context_definition * The context definition of the context on the plugin. * @param \Drupal\Core\TypedData\DataDefinitionInterface $provided * The data definition of the mapped variable to the context. * @param string $context_name * The name of the context on the plugin. * @param \Drupal\rules\Engine\IntegrityViolationList $violation_list * The list of violations where new ones will be added. */ protected function checkDataTypeCompatible(CoreContextDefinitionInterface $context_definition, DataDefinitionInterface $provided, $context_name, IntegrityViolationList $violation_list) { // Compare data types. For now, fail if they are not equal. // @todo: Add support for matching based upon type-inheritance. $target_type = $context_definition->getDataDefinition()->getDataType(); // Special case any and entity target types for now. if ($target_type == 'any' || $target_type == 'entity' && strpos($provided->getDataType(), 'entity:') !== FALSE) { return; } if ($target_type != $provided->getDataType()) { $expected_type_problem = $context_definition->getDataDefinition()->getDataType(); $violation = new IntegrityViolation(); $violation->setMessage($this->t('Expected a @expected_type data type for context %context_name but got a @provided_type data type instead.', ['@expected_type' => $expected_type_problem, '%context_name' => $context_definition->getLabel(), '@provided_type' => $provided->getDataType()])); $violation->setContextName($context_name); $violation->setUuid($this->getUuid()); $violation_list->add($violation); } }