ConditionAggregate.php in Drupal 9
File
core/lib/Drupal/Core/Entity/Query/Sql/ConditionAggregate.php
View source
<?php
namespace Drupal\Core\Entity\Query\Sql;
use Drupal\Core\Database\Query\SelectInterface;
use Drupal\Core\Entity\Query\ConditionAggregateBase;
use Drupal\Core\Entity\Query\ConditionAggregateInterface;
use Drupal\Core\Entity\Query\QueryBase;
class ConditionAggregate extends ConditionAggregateBase {
public function compile($conditionContainer) {
$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 = $sql_query
->getConnection()
->condition($condition['field']
->getConjunction());
$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_class = QueryBase::getClass($this->namespaces, 'Condition');
$condition_class::translateCondition($condition, $sql_query, $tables
->isFieldCaseSensitive($condition['field']));
$function = $condition['function'];
$placeholder = ':db_placeholder_' . $conditionContainer
->nextPlaceholder();
$sql_field_escaped = '[' . str_replace('.', '].[', $field) . ']';
$conditionContainer
->having("{$function}({$sql_field_escaped}) {$condition['operator']} {$placeholder}", [
$placeholder => $condition['value'],
]);
}
}
}
public function exists($field, $function, $langcode = NULL) {
return $this
->condition($field, $function, NULL, 'IS NOT NULL', $langcode);
}
public function notExists($field, $function, $langcode = NULL) {
return $this
->condition($field, $function, NULL, 'IS NULL', $langcode);
}
}