abstract class ConditionBase

Common code for all implementations of the entity query condition interface.

Hierarchy

Expanded class hierarchy of ConditionBase

1 file declares its use of ConditionBase
Condition.php in drupal/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/Entity/Condition.php
Definition of Drupal\field_sql_storage\Query\ConditionSql.

File

drupal/core/lib/Drupal/Core/Entity/Query/ConditionBase.php, line 13
Definition of Drupal\Core\Entity\Query\ConditionBase.

Namespace

Drupal\Core\Entity\Query
View source
abstract class ConditionBase implements ConditionInterface {

  /**
   * Array of conditions.
   *
   * @var array
   */
  protected $conditions = array();

  /**
   * Constructs a Condition object.
   *
   * @param string $conjunction
   *   The operator to use to combine conditions: 'AND' or 'OR'.
   */
  public function __construct($conjunction = 'AND') {
    $this->conjunction = $conjunction;
  }

  /**
   * Implements Drupal\Core\Entity\Query\ConditionInterface::getConjunction().
   */
  public function getConjunction() {
    return $this->conjunction;
  }

  /**
   * Implements Countable::count().
   */
  public function count() {
    return count($this->conditions) - 1;
  }

  /**
   * Implements Drupal\Core\Entity\Query\ConditionInterface::compile().
   */
  public function condition($field, $value = NULL, $operator = NULL, $langcode = NULL) {
    $this->conditions[] = array(
      'field' => $field,
      'value' => $value,
      'operator' => $operator,
      'langcode' => $langcode,
    );
    return $this;
  }

  /**
   * Implements Drupal\Core\Entity\Query\ConditionInterface::conditions().
   */
  public function &conditions() {
    return $this->conditions;
  }

  /**
   * Makes sure condition groups are cloned as well.
   */
  function __clone() {
    foreach ($this->conditions as $key => $condition) {
      if ($condition['field'] instanceof ConditionInterface) {
        $this->conditions[$key]['field'] = clone $condition['field'];
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConditionBase::$conditions protected property Array of conditions.
ConditionBase::condition public function Implements Drupal\Core\Entity\Query\ConditionInterface::compile(). Overrides ConditionInterface::condition
ConditionBase::conditions public function Implements Drupal\Core\Entity\Query\ConditionInterface::conditions(). Overrides ConditionInterface::conditions
ConditionBase::count public function Implements Countable::count(). Overrides ConditionInterface::count
ConditionBase::getConjunction public function Implements Drupal\Core\Entity\Query\ConditionInterface::getConjunction(). Overrides ConditionInterface::getConjunction
ConditionBase::__clone function Makes sure condition groups are cloned as well.
ConditionBase::__construct public function Constructs a Condition object.
ConditionInterface::compile public function Compiles this conditional clause.
ConditionInterface::exists public function Queries for the existence of a field.
ConditionInterface::notExists public function Queries for the existence of a field.