diff --git a/core/lib/Drupal/Core/Database/Query/Condition.php b/core/lib/Drupal/Core/Database/Query/Condition.php index ec541c1..00e9015 100644 --- a/core/lib/Drupal/Core/Database/Query/Condition.php +++ b/core/lib/Drupal/Core/Database/Query/Condition.php @@ -165,7 +165,7 @@ public function compile(Connection $connection, PlaceholderInterface $queryPlace foreach ($conditions as $condition) { // Process field. if ($condition['field'] instanceof ConditionInterface) { - // Left hand part is a structured condition or a subquery: compile, + // Left hand part is a structured condition or a subquery. Compile, // put brackets around it (if it is a query), and collect any // arguments. $condition['field']->compile($connection, $queryPlaceholder); @@ -174,25 +174,29 @@ public function compile(Connection $connection, PlaceholderInterface $queryPlace $field_fragment = '(' . $field_fragment . ')'; } $arguments += $condition['field']->arguments(); + // If the operator and value were not passed in to the + // @see ConditionInterface::condition() method (and thus have the + // default value as defined over there) it is assumed to be a valid + // condition on its own: ignore the operator and value parts. + $ignore_operator = $condition['operator'] === '=' && $condition['value'] === NULL; } else if (!isset($condition['operator'])) { // Left hand part is a literal string added with the // @see ConditionInterface::where() method. Put brackets around // the snippet and collect the arguments from the value part. + // Also ignore the operator and value parts. $field_fragment = '(' . $condition['field'] . ')'; $arguments += $condition['value']; + $ignore_operator = TRUE; } else { - // Left hand part is a normal field: add it as is. + // Left hand part is a normal field. Add it as is. $field_fragment = $condition['field']; + $ignore_operator = FALSE; } // Process operator. - if ($condition['value'] === NULL && $condition['field'] instanceof ConditionInterface && $condition['operator'] === '=') { - // If the operator and value were not passed in (and thus have the - // default value as defined by the condition() method) and the field - // is a Condition, it is assumed to be a valid condition on its own: - // ignore the operator and value parts. + if ($ignore_operator) { $operator = array('operator' => '', 'use_value' => FALSE); } else { @@ -255,14 +259,14 @@ public function compile(Connection $connection, PlaceholderInterface $queryPlace $value_fragment = array(); foreach ($condition['value'] as $value) { if ($value instanceof ConditionInterface) { - // Right hand part is a subquery: compile, assure that brackets + // Right hand part is a subquery. Compile, assure that brackets // are put around it and collect any arguments. $value->compile($connection, $queryPlaceholder); $value_fragment[] = '(' . (string) $value . ')'; $arguments += $value->arguments(); } else { - // Right hand part is a normal value: replace the value with a + // Right hand part is a normal value. Replace the value with a // placeholder and add the value as an argument. $placeholder = ':db_condition_placeholder_' . $queryPlaceholder->nextPlaceholder(); $value_fragment[] = $placeholder;