function Condition::condition
Same name in other branches
- 9 core/lib/Drupal/Core/Database/Query/Condition.php \Drupal\Core\Database\Query\Condition::condition()
- 8.9.x core/lib/Drupal/Core/Database/Query/Condition.php \Drupal\Core\Database\Query\Condition::condition()
- 11.x core/lib/Drupal/Core/Database/Query/Condition.php \Drupal\Core\Database\Query\Condition::condition()
Overrides ConditionInterface::condition
4 calls to Condition::condition()
- Condition::exists in core/
lib/ Drupal/ Core/ Database/ Query/ Condition.php - Condition::isNotNull in core/
lib/ Drupal/ Core/ Database/ Query/ Condition.php - Condition::isNull in core/
lib/ Drupal/ Core/ Database/ Query/ Condition.php - Condition::notExists in core/
lib/ Drupal/ Core/ Database/ Query/ Condition.php
File
-
core/
lib/ Drupal/ Core/ Database/ Query/ Condition.php, line 101
Class
- Condition
- Generic class for a series of conditions in a query.
Namespace
Drupal\Core\Database\QueryCode
public function condition($field, $value = NULL, $operator = '=') {
if (empty($operator)) {
$operator = '=';
}
if (empty($value) && is_array($value)) {
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,
'value' => $value,
'operator' => $operator,
];
$this->changed = TRUE;
return $this;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.