/** * Implements \Drupal\Core\Entity\Query\ConditionInterface::compile(). */ 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. $sql_query = $conditionContainer instanceof SelectInterface ? $conditionContainer : $conditionContainer->sqlQuery; $tables = new Tables($sql_query); foreach ($this->conditions as $condition) { if ($condition['field'] instanceof ConditionAggregateInterface) { $sql_condition = new SqlCondition($condition['field']->getConjunction()); // Add the SQL query to the object before calling this method again. $sql_condition->sqlQuery = $sql_query; $condition['field']->compile($sql_condition); $sql_query->condition($sql_condition); } else { $type = strtoupper($this->conjunction) == 'OR' || $condition['operator'] == 'IS NULL' ? 'LEFT' : 'INNER'; $field = $tables->addField($condition['field'], $type, $condition['langcode']); Condition::translateCondition($condition, $sql_query, $tables->isFieldCaseSensitive($condition['field'])); $function = $condition['function']; $placeholder = ':db_placeholder_' . $conditionContainer->nextPlaceholder(); $conditionContainer->having("{$function}({$field}) {$condition['operator']} {$placeholder}", array($placeholder => $condition['value'])); } } }
/** * {@inheritdoc} */ public static function translateCondition(&$condition, SelectInterface $sql_query, $case_sensitive) { if (is_array($condition['value']) && $case_sensitive === FALSE) { $condition['where'] = 'LOWER(' . $sql_query->escapeField($condition['real_field']) . ') ' . $condition['operator'] . ' ('; $condition['where_args'] = []; $n = 1; // Only use the array values in case an associative array is passed as an // argument following similar pattern in // \Drupal\Core\Database\Connection::expandArguments(). foreach ($condition['value'] as $value) { $condition['where'] .= 'LOWER(:value' . $n . '),'; $condition['where_args'][':value' . $n] = $value; $n++; } $condition['where'] = trim($condition['where'], ','); $condition['where'] .= ')'; return; } parent::translateCondition($condition, $sql_query, $case_sensitive); }