You are here

public function HeartbeatEntityQuery::condition in Heartbeat 8

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();

  ->condition('tags.5.value', 'news')

This will require condition to be satisfied on a specific delta of the field. The condition above will require the 6th value of the field to match the provided value. Further, it's possible to create a condition on the delta itself by using '%delta'. For example,


  ->condition('tags.%delta', 5)

will find only entities which have at least six tags. Finally, the condition on the delta itself accompanied with a condition on the value will require the value to appear in the specific delta range. For example,


  ->condition('tags.%delta', 0, '>'))
  ->condition('tags.%delta.value', 'news'))

will only find the "news" tag if it is not the first value. It should be noted that conditions on specific deltas and delta ranges are only supported when querying content entities.

Parameters

$field: Name of the field being queried. It must contain a field name, optionally followed by a column name. The column can be the reference property, usually "entity", for reference fields and that can be followed similarly by a field name and so on. Additionally, the target entity type can be specified by appending the ":target_entity_type_id" to "entity". Some examples:

  • nid
  • tags.value
  • tags
  • tags.entity.name
  • tags.entity:taxonomy_term.name
  • uid.entity.name
  • uid.entity:user.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. In order to limit the condition to a specific item a numeric delta should be added between the field name and the column name.

$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

File

src/HeartbeatEntityQuery.php, line 200

Class

HeartbeatEntityQuery
Created by IntelliJ IDEA. User: logicp Date: 5/28/17 Time: 1:37 PM

Code

public function condition($field, $value = NULL, $operator = NULL, $langcode = NULL) {

  // TODO: Implement condition() method.
}