function ConditionExpression::executeWithState

Overrides ExpressionInterface::executeWithState

File

src/Plugin/RulesExpression/ConditionExpression.php, line 114

Class

ConditionExpression
Defines an executable condition expression.

Namespace

Drupal\rules\Plugin\RulesExpression

Code

public function executeWithState(ExecutionStateInterface $state) {
    $condition = $this->conditionManager
        ->createInstance($this->configuration['condition_id'], [
        'negate' => $this->configuration['negate'],
    ]);
    $this->prepareContext($condition, $state);
    $result = $condition->evaluate();
    if ($this->isNegated()) {
        $result = !$result;
    }
    $this->rulesDebugLogger
        ->info('The condition %name evaluated to %bool.', [
        '%name' => $this->getLabel(),
        '%bool' => $result ? 'TRUE' : 'FALSE',
        'element' => $this,
    ]);
    // Now that the condition has been executed it can provide additional
    // context which we will have to pass back in the evaluation state.
    $this->addProvidedContext($condition, $state);
    return $result;
}