public function Condition::compile

Same name in this branch
  1. 8.x drupal/core/lib/Drupal/Core/Database/Query/Condition.php \Drupal\Core\Database\Query\Condition::compile()
  2. 8.x drupal/core/lib/Drupal/Core/Config/Entity/Query/Condition.php \Drupal\Core\Config\Entity\Query\Condition::compile()
  3. 8.x drupal/core/modules/field_sql_storage/lib/Drupal/field_sql_storage/Entity/Condition.php \Drupal\field_sql_storage\Entity\Condition::compile()

Implements Drupal\Core\Entity\Query\ConditionInterface::compile().

Overrides ConditionInterface::compile

File

drupal/core/modules/field_sql_storage/lib/Drupal/field_sql_storage/Entity/Condition.php, line 20
Definition of Drupal\field_sql_storage\Query\ConditionSql.

Class

Condition

Namespace

Drupal\field_sql_storage\Entity

Code

public function compile($conditionContainer) {

  // If this is not the top level condition group then the sql query is
  // added to the $conditionContainer object by this function itself. The
  // SQL query object is only necessary to pass to Query::addField() so it
  // can join tables as necessary. On the other hand, conditions need to be
  // added to the $conditionContainer object to keep grouping.
  $sqlQuery = $conditionContainer instanceof SelectInterface ? $conditionContainer : $conditionContainer->sqlQuery;
  $tables = new Tables($sqlQuery);
  foreach ($this->conditions as $condition) {
    if ($condition['field'] instanceof ConditionInterface) {
      $sqlCondition = new SqlCondition($condition['field']
        ->getConjunction());

      // Add the SQL query to the object before calling this method again.
      $sqlCondition->sqlQuery = $sqlQuery;
      $condition['field']
        ->compile($sqlCondition);
      $sqlQuery
        ->condition($sqlCondition);
    }
    else {
      $type = strtoupper($this->conjunction) == 'OR' || $condition['operator'] == 'IS NULL' ? 'LEFT' : 'INNER';
      $this
        ->translateCondition($condition);
      $field = $tables
        ->addField($condition['field'], $type, $condition['langcode']);
      $conditionContainer
        ->condition($field, $condition['value'], $condition['operator']);
    }
  }
}