Condition
class Condition implements ConditionInterface, Countable (View source)
Generic class for a series of conditions in a query.
Properties
| static protected | $conditionOperatorMap | Provides a map of condition operators to condition operator options. |
|
| protected array | $conditions | Array of conditions. |
|
| protected array | $arguments | Array of arguments. |
|
| protected bool | $changed | Whether the conditions have been changed. |
|
| protected string | $queryPlaceholderIdentifier | The identifier of the query placeholder this condition has been compiled against. |
|
| protected string | $stringVersion | Contains the string version of the Condition. |
Methods
Constructs a Condition object.
Implements Countable::count().
Helper function: builds the most common conditional clauses.
Adds an arbitrary WHERE clause to the query.
Sets a condition that is always false.
Gets the, possibly nested, list of conditions in this conditional clause.
Gets a complete list of all values to insert into the prepared statement.
Compiles the saved conditions for later retrieval.
Check whether a condition has been previously compiled.
Implements PHP magic __toString method to convert the conditions to string.
PHP magic __clone() method.
Gets any special processing requirements for the condition operator.
Creates an object holding a group of conditions.
Creates a new group of conditions ANDed together.
Creates a new group of conditions ORed together.
Details
__construct(string $conjunction, bool $trigger_deprecation = TRUE)
deprecated
deprecated
Constructs a Condition object.
count()
Implements Countable::count().
Returns the size of this conditional. The size of the conditional is the size of its conditional array minus one, because one element is the conjunction.
$this
condition(string|ConditionInterface $field, string|array|SelectInterface|null $value = NULL, string|null $operator = '=')
Helper function: builds the most common conditional clauses.
This method takes 1 to 3 parameters.
If called with 1 parameter, it should be a ConditionInterface that in itself forms a valid where clause. Use e.g. to build clauses with nested ANDs and ORs.
If called with 2 parameters, they are taken as $field and $value with $operator having a value of =.
Do not use this method to test for NULL values. Instead, use QueryConditionInterface::isNull() or QueryConditionInterface::isNotNull().
To improve readability, the operators EXISTS and NOT EXISTS have their own utility method defined.
Drupal considers LIKE case insensitive and the following is often used to tell the database that case insensitive equivalence is desired:
$this
where(string $snippet, array $args = [])
Adds an arbitrary WHERE clause to the query.
$this
isNull(string|SelectInterface $field)
Sets a condition that the specified field be NULL.
$this
isNotNull(string|SelectInterface $field)
Sets a condition that the specified field be NOT NULL.
$this
exists(SelectInterface $select)
Sets a condition that the specified subquery returns values.
$this
notExists(SelectInterface $select)
Sets a condition that the specified subquery returns no values.
$this
alwaysFalse()
Sets a condition that is always false.
array
conditions()
Gets the, possibly nested, list of conditions in this conditional clause.
This method returns by reference. That allows alter hooks to access the data structure directly and manipulate it before it gets compiled.
The data structure that is returned is an indexed array of entries, where each entry looks like the following:
An
arguments()
Gets a complete list of all values to insert into the prepared statement.
compile(Connection $connection, PlaceholderInterface $queryPlaceholder)
Compiles the saved conditions for later retrieval.
This method does not return anything, but simply prepares data to be retrieved via __toString() and arguments().
true
compiled()
Check whether a condition has been previously compiled.
string
__toString()
Implements PHP magic __toString method to convert the conditions to string.
__clone()
PHP magic __clone() method.
Only copies fields that implement Drupal\Core\Database\Query\ConditionInterface. Also sets $this->changed to TRUE.
protected array
mapConditionOperator(string $operator)
Gets any special processing requirements for the condition operator.
Some condition types require special processing, such as IN, because the value data they pass in is not a simple value. This is a simple overridable lookup function.
ConditionInterface
conditionGroupFactory($conjunction = 'AND')
Creates an object holding a group of conditions.
See andConditionGroup() and orConditionGroup() for more.
ConditionInterface
andConditionGroup()
Creates a new group of conditions ANDed together.
ConditionInterface
orConditionGroup()
Creates a new group of conditions ORed together.