Verified Commit 7e1dcd65 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #2823910 by daffie, pwolanin, smustgrave, neclimdul, larowlan, dawehner:...

Issue #2823910 by daffie, pwolanin, smustgrave, neclimdul, larowlan, dawehner: DBTNG/EQ condition works inconsistently with arrays

(cherry picked from commit 485604fe)
parent d0144731
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -106,9 +106,15 @@ public function condition($field, $value = NULL, $operator = '=') {
      throw new InvalidQueryException(sprintf("Query condition '%s %s ()' cannot be empty.", $field, $operator));
    }
    if (is_array($value) && in_array($operator, ['=', '<', '>', '<=', '>=', 'IS NULL', 'IS NOT NULL'], TRUE)) {
      if (count($value) > 1) {
        $value = implode(', ', $value);
        throw new InvalidQueryException(sprintf("Query condition '%s %s %s' must have an array compatible operator.", $field, $operator, $value));
      }
      else {
        $value = $value[0];
        @trigger_error('Calling ' . __METHOD__ . '() without an array compatible operator is deprecated in drupal:10.1.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/3350985', E_USER_DEPRECATED);
      }
    }

    $this->conditions[] = [
      'field' => $field,
+14 −0
Original line number Diff line number Diff line
@@ -627,4 +627,18 @@ public function testNonArrayOperatorWithArrayValueCondition($operator, $operator
      ->execute();
  }

  /**
   * Tests thrown exception for non array operator conditions with array value.
   *
   * @dataProvider providerNonArrayOperatorWithArrayValueCondition
   * @group legacy
   */
  public function testNonArrayOperatorWithArrayValueConditionDeprecated($operator, $operator_in_exception_message) {
    $this->expectDeprecation('Calling Drupal\Core\Database\Query\Condition::condition() without an array compatible operator is deprecated in drupal:10.1.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/3350985');
    $this->connection->select('test', 't')
      ->fields('t')
      ->condition('age', [26], $operator)
      ->execute();
  }

}