You are here

class AndExpression in Rules 8.3

Evaluates a group of conditions with a logical AND.

Plugin annotation


@RulesExpression(
  id = "rules_and",
  label = @Translation("Condition set (AND)"),
  form_class = "\Drupal\rules\Form\Expression\ConditionContainerForm"
)

Hierarchy

Expanded class hierarchy of AndExpression

2 files declare their use of AndExpression
AndExpressionTest.php in tests/src/Unit/AndExpressionTest.php
RuleExpressionTest.php in tests/src/Unit/RuleExpressionTest.php

File

src/Plugin/RulesExpression/AndExpression.php, line 17

Namespace

Drupal\rules\Plugin\RulesExpression
View source
class AndExpression extends ConditionExpressionContainer {

  /**
   * Returns whether there is a configured condition.
   *
   * @todo Remove this once we added the API to access configured conditions.
   *
   * @return bool
   *   TRUE if there are no conditions, FALSE otherwise.
   */
  public function isEmpty() {
    return empty($this->conditions);
  }

  /**
   * {@inheritdoc}
   */
  public function evaluate(ExecutionStateInterface $state) {

    // Use the iterator to ensure the conditions are sorted.
    foreach ($this as $condition) {

      /** @var \Drupal\rules\Engine\ExpressionInterface $condition */
      if (!$condition
        ->executeWithState($state)) {
        $this->rulesDebugLogger
          ->info('%label evaluated to %result.', [
          '%label' => $this
            ->getLabel(),
          '%result' => 'FALSE',
        ]);
        return FALSE;
      }
    }
    $this->rulesDebugLogger
      ->info('%label evaluated to %result.', [
      '%label' => $this
        ->getLabel(),
      '%result' => 'TRUE',
    ]);

    // An empty AND should return FALSE. Otherwise, if all conditions evaluate
    // to TRUE we return TRUE.
    return !empty($this->conditions);
  }

  /**
   * {@inheritdoc}
   */
  protected function allowsMetadataAssertions() {

    // If the AND is not negated, all child-expressions must be executed - thus
    // assertions can be added it.
    return !$this
      ->isNegated();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AndExpression::allowsMetadataAssertions protected function Determines whether child-expressions are allowed to assert metadata. Overrides ExpressionContainerBase::allowsMetadataAssertions
AndExpression::evaluate public function Returns the final result after executing the conditions. Overrides ConditionExpressionContainer::evaluate
AndExpression::isEmpty public function Returns whether there is a configured condition.
ConditionExpressionContainer::$conditions protected property List of conditions that are evaluated.
ConditionExpressionContainer::addCondition public function Creates a condition expression and adds it to the container. Overrides ConditionExpressionContainerInterface::addCondition
ConditionExpressionContainer::addExpressionObject public function Adds an expression object. Overrides ExpressionContainerInterface::addExpressionObject
ConditionExpressionContainer::deleteExpression public function Deletes an expression identified by the specified UUID in the container. Overrides ExpressionContainerInterface::deleteExpression
ConditionExpressionContainer::executeWithState public function Execute the expression with a given Rules state. Overrides ExpressionInterface::executeWithState
ConditionExpressionContainer::getConfiguration public function Gets this plugin's configuration. Overrides ExpressionBase::getConfiguration
ConditionExpressionContainer::getExpression public function Looks up the expression by UUID in this container. Overrides ExpressionContainerInterface::getExpression
ConditionExpressionContainer::getIterator public function
ConditionExpressionContainer::isNegated public function Determines whether condition result will be negated. Overrides ConditionExpressionInterface::isNegated
ConditionExpressionContainer::negate public function Negates the result after evaluating this condition. Overrides ConditionExpressionInterface::negate
ConditionExpressionContainer::__clone public function PHP magic __clone function.
ConditionExpressionContainer::__construct public function Constructs a new class instance. Overrides ExpressionBase::__construct
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
ExpressionBase::$configEntityId protected property The config entity this expression is associated with, if any.
ExpressionBase::$configuration protected property The plugin configuration. Overrides PluginBase::$configuration
ExpressionBase::$root protected property The root expression if this object is nested.
ExpressionBase::$uuid protected property The UUID of this expression.
ExpressionBase::$weight protected property The weight (list order) of this expression.
ExpressionBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies
ExpressionBase::defaultConfiguration public function Gets default configuration for this plugin. Overrides ConfigurableInterface::defaultConfiguration 2
ExpressionBase::execute public function Executes a rules expression. Overrides ExecutableInterface::execute
ExpressionBase::getFormHandler public function Returns the form handling class for this expression. Overrides ExpressionInterface::getFormHandler 2
ExpressionBase::getLabel public function The label of this expression element that can be shown in the UI. Overrides ExpressionInterface::getLabel 2
ExpressionBase::getRoot public function Returns the root expression if this expression is nested. Overrides ExpressionInterface::getRoot
ExpressionBase::getUuid public function Returns the UUID of this expression if it is nested in another expression. Overrides ExpressionInterface::getUuid
ExpressionBase::getWeight public function Returns the list order of this expression. Overrides ExpressionInterface::getWeight
ExpressionBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration 2
ExpressionBase::setRoot public function Set the root expression for this expression if it is nested. Overrides ExpressionInterface::setRoot
ExpressionBase::setUuid public function Sets the UUID of this expression in an expression tree. Overrides ExpressionInterface::setUuid
ExpressionBase::setWeight public function Sets the list order of this expression in an expression tree. Overrides ExpressionInterface::setWeight
ExpressionContainerBase::$expressionManager protected property The expression manager.
ExpressionContainerBase::$rulesDebugLogger protected property The rules debug logger channel.
ExpressionContainerBase::addExpression public function Creates and adds an expression. Overrides ExpressionContainerInterface::addExpression
ExpressionContainerBase::checkIntegrity public function Verifies that this expression is configured correctly. Overrides ExpressionInterface::checkIntegrity 1
ExpressionContainerBase::create public static function
ExpressionContainerBase::prepareExecutionMetadataState public function Prepares the execution metadata state by adding metadata to it. Overrides ExpressionInterface::prepareExecutionMetadataState
ExpressionContainerBase::prepareExecutionMetadataStateAfterTraversal protected function Prepares execution metadata state after traversing through children. 1
ExpressionContainerBase::prepareExecutionMetadataStateBeforeTraversal protected function Prepares execution metadata state before traversing through children. 1
ExpressionContainerBase::sortByWeightProperty public static function Sorts an array of expressions by 'weight' property.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.