You are here

public function QueryBase::condition in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Entity/Query/QueryBase.php \Drupal\Core\Entity\Query\QueryBase::condition()

Add a condition to the query or a condition group.

For example, to find all entities containing both the Turkish 'merhaba' and the Polish 'siema' within a 'greetings' text field:


  $entity_ids = \Drupal::entityQuery($entity_type)
    ->condition('greetings', 'merhaba', '=', 'tr');
    ->condition('greetings.value', 'siema', '=', 'pl');
    ->execute();
  $entity_ids = $query->execute();

Parameters

$field: Name of the field being queried. It must contain a field name, optionally followed by a column name. The column can be "entity" for reference fields and that can be followed similarly by a field name and so on. Some examples:

  • nid
  • tags.value
  • tags
  • uid.entity.name

"tags" "is the same as "tags.value" as value is the default column. If two or more conditions have the same field names they apply to the same delta within that field.

$value: The value for $field. In most cases, this is a scalar and it's treated as case-insensitive. For more complex operators, it is an array. The meaning of each element in the array is dependent on $operator.

$operator: Possible values:

  • '=', '<>', '>', '>=', '<', '<=', 'STARTS_WITH', 'CONTAINS', 'ENDS_WITH': These operators expect $value to be a literal of the same type as the column.
  • 'IN', 'NOT IN': These operators expect $value to be an array of literals of the same type as the column.
  • 'BETWEEN': This operator expects $value to be an array of two literals of the same type as the column.

$langcode: Language code (optional). If omitted, any translation satisfies the condition. However, if two or more conditions omit the langcode within one condition group then they are presumed to apply to the same translation. If within one condition group one condition has a langcode and another does not they are not presumed to apply to the same translation.

Return value

\Drupal\Core\Entity\Query\QueryInterface

Overrides QueryInterface::condition

See also

\Drupal\Core\Entity\Query\andConditionGroup

\Drupal\Core\Entity\Query\orConditionGroup

1 call to QueryBase::condition()
Query::condition in core/lib/Drupal/Core/Config/Entity/Query/Query.php
Overrides \Drupal\Core\Entity\Query\QueryBase::condition().
1 method overrides QueryBase::condition()
Query::condition in core/lib/Drupal/Core/Config/Entity/Query/Query.php
Overrides \Drupal\Core\Entity\Query\QueryBase::condition().

File

core/lib/Drupal/Core/Entity/Query/QueryBase.php, line 164
Contains \Drupal\Core\Entity\Query\QueryBase.

Class

QueryBase
The base entity query class.

Namespace

Drupal\Core\Entity\Query

Code

public function condition($property, $value = NULL, $operator = NULL, $langcode = NULL) {
  $this->condition
    ->condition($property, $value, $operator, $langcode);
  return $this;
}