Drupal 8  8.0.2
QueryInterface Interface Reference
Inheritance diagram for QueryInterface:

Public Member Functions

 getEntityTypeId ()
 
 condition ($field, $value=NULL, $operator=NULL, $langcode=NULL)
 
 exists ($field, $langcode=NULL)
 
 notExists ($field, $langcode=NULL)
 
 pager ($limit=10, $element=NULL)
 
 range ($start=NULL, $length=NULL)
 
 sort ($field, $direction= 'ASC', $langcode=NULL)
 
 count ()
 
 tableSort (&$headers)
 
 accessCheck ($access_check=TRUE)
 
 execute ()
 
 andConditionGroup ()
 
 orConditionGroup ()
 
 currentRevision ()
 
 allRevisions ()
 
- Public Member Functions inherited from AlterableInterface
 addTag ($tag)
 
 hasTag ($tag)
 
 hasAllTags ()
 
 hasAnyTag ()
 
 addMetaData ($key, $object)
 
 getMetaData ($key)
 

Detailed Description

Interface for entity queries.

Never instantiate classes implementing this interface directly. Always use the QueryFactory class.

Member Function Documentation

accessCheck (   $access_check = TRUE)
Returns
The called object.

Implemented in QueryBase.

allRevisions ( )

Queries all the revisions.

Returns
$this

Implemented in QueryBase.

andConditionGroup ( )

Creates a new group of conditions ANDed together.

For example, consider a drawing entity type with a 'figures' multi-value field containing 'shape' and 'color' columns. To find all drawings containing both a red triangle and a blue circle:

$query = \Drupal::entityQuery('drawing');
$group = $query->andConditionGroup()
->condition('figures.color', 'red')
->condition('figures.shape', 'triangle');
$query->condition($group);
$group = $query->andConditionGroup()
->condition('figures.color', 'blue')
->condition('figures.shape', 'circle');
$query->condition($group);
$entity_ids = $query->execute();
Returns

Implemented in QueryBase.

condition (   $field,
  $value = NULL,
  $operator = NULL,
  $langcode = NULL 
)

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
$fieldName 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.
$valueThe 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.
$operatorPossible 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.
$langcodeLanguage 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.
Returns
See Also

Implemented in QueryBase, and Query.

Referenced by EntityStorageBase\buildPropertyQuery().

Here is the caller graph for this function:

count ( )

Makes this a count query.

For count queries, execute() returns the number entities found.

Returns
The called object.

Implemented in QueryBase.

currentRevision ( )

Queries the current revision.

Returns
$this

Implemented in QueryBase.

execute ( )

Execute the query.

Returns
int|array Returns an integer for count queries or an array of ids. The values of the array are always entity ids. The keys will be revision ids if the entity supports revision and entity ids if not.

Implemented in QueryAggregateInterface, Query, Query, Query, QueryAggregate, and Query.

exists (   $field,
  $langcode = NULL 
)

Queries for a non-empty value on a field.

Parameters
$fieldName of a field.
$langcodeLanguage code (optional).
Returns

Implemented in QueryBase.

getEntityTypeId ( )

Gets the ID of the entity type for this query.

Returns
string

Implemented in QueryBase.

notExists (   $field,
  $langcode = NULL 
)

Queries for an empty field.

Parameters
$field.Name of a field.
$langcodeLanguage code (optional).
Returns

Implemented in QueryBase.

orConditionGroup ( )

Creates a new group of conditions ORed together.

For example, consider a map entity with an 'attributes' field containing 'building_type' and 'color' columns. To find all green and red bikesheds:

$query = \Drupal::entityQuery('map');
$group = $query->orConditionGroup()
->condition('attributes.color', 'red')
->condition('attributes.color', 'green');
$entity_ids = $query
->condition('attributes.building_type', 'bikeshed')
->condition($group)
->execute();

Note that this particular example can be simplified:

$entity_ids = $query
->condition('attributes.color', array('red', 'green'))
->condition('attributes.building_type', 'bikeshed')
->execute();
Returns

Implemented in QueryBase.

pager (   $limit = 10,
  $element = NULL 
)

Enables a pager for the query.

Parameters
$limitAn integer specifying the number of elements per page. If passed a false value (FALSE, 0, NULL), the pager is disabled.
$elementAn optional integer to distinguish between multiple pagers on one page. If not provided, one is automatically calculated.
Returns
The called object.

Implemented in QueryBase.

range (   $start = NULL,
  $length = NULL 
)
Parameters
null$start
null$length
Returns
The called object.

Implemented in QueryBase.

sort (   $field,
  $direction = 'ASC',
  $langcode = NULL 
)
Parameters
$fieldName of a field.
string$direction
$langcodeLanguage code (optional).
Returns
The called object.

Implemented in QueryBase.

tableSort ( $headers)

Enables sortable tables for this query.

Parameters
$headersAn array of headers of the same structure as described in template_preprocess_table(). Use a 'specifier' in place of a 'field' to specify what to sort on. This can be an entity or a field as described in condition().
Returns
The called object.

Implemented in QueryBase.


The documentation for this interface was generated from the following file: