You are here

public function ActionExpression::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 ExpressionInterface::checkIntegrity

See also

::prepareExecutionMetadataState()

File

src/Plugin/RulesExpression/ActionExpression.php, line 147

Class

ActionExpression
Provides an executable action expression.

Namespace

Drupal\rules\Plugin\RulesExpression

Code

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