abstract class QueryBase implements QueryInterface (View source)

The base entity query class.

Properties

protected string $entityTypeId

The entity type this query runs against.

protected EntityTypeInterface $entityType

Information about the entity type.

protected array $sort

The list of sorts.

protected bool $count

TRUE if this is a count query, FALSE if it isn't.

protected ConditionInterface $condition Conditions.
protected array $aggregate

The list of aggregate expressions.

protected array $groupBy

The list of columns to group on.

protected ConditionAggregateInterface $conditionAggregate

Aggregate Conditions

protected array $sortAggregate

The list of sorts over the aggregate results.

protected array $range

The query range.

protected array $alterMetaData

The query metadata for alter purposes.

protected array $alterTags

The query tags.

protected bool $accessCheck

Whether access check is requested or not. Defaults to TRUE.

protected bool $allRevisions

Flag indicating whether to query the current revision or all revisions.

protected bool $latestRevision

Flag indicating whether to query the latest revision.

protected array $pager

The query pager data.

protected array $namespaces

List of potential namespaces of the classes belonging to this query.

Methods

__construct(EntityTypeInterface $entity_type, string $conjunction, array $namespaces)

Constructs this object.

string
getEntityTypeId()

Gets the ID of the entity type for this query.

$this
condition($property, $value = NULL, $operator = NULL, $langcode = NULL)

Add a condition to the query or a condition group.

$this
exists($property, $langcode = NULL)

Queries for a non-empty value on a field.

$this
notExists($property, $langcode = NULL)

Queries for an empty field.

$this
range(null $start = NULL, null $length = NULL)

No description

conditionGroupFactory(string $conjunction = 'AND')

Creates an object holding a group of conditions.

andConditionGroup()

Creates a new group of conditions ANDed together.

orConditionGroup()

Creates a new group of conditions ORed together.

$this
sort($field, string $direction = 'ASC', $langcode = NULL)

No description

$this
count()

Makes this a count query.

$this
accessCheck($access_check = TRUE)

No description

$this
currentRevision()

Queries the current revision.

$this
latestRevision()

Queries the latest revision.

$this
allRevisions()

Queries all the revisions.

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

Enables a pager for the query.

initializePager()

Gets the total number of results and initialize a pager for the query.

$this
tableSort($headers)

Enables sortable tables for this query.

__clone()

Makes sure that the Condition object is cloned as well.

$this
addTag($tag)

Adds a tag to a query.

true
hasTag($tag)

Determines if a given query has a given tag.

true
hasAllTags()

Determines if a given query has all specified tags.

true
hasAnyTag()

Determines if a given query has any specified tag.

$this
addMetaData($key, $object)

Adds additional metadata to the query.

The
getMetaData($key)

Retrieves a given piece of metadata.

aggregate($field, $function, $langcode = NULL, $alias = NULL)

{@inheritdoc}

conditionAggregate($field, $function = NULL, $value = NULL, $operator = '=', $langcode = NULL)

{@inheritdoc}

sortAggregate($field, $function, $direction = 'ASC', $langcode = NULL)

{@inheritdoc}

groupBy($field, $langcode = NULL)

{@inheritdoc}

string
getAggregationAlias(string $field, string $function)

Generates an alias for a field and its aggregated function.

static array
getNamespaces($object)

Gets a list of namespaces of the ancestors of a class.

static string
getClass(array $namespaces, string $short_class_name)

Finds a class in a list of namespaces.

Details

__construct(EntityTypeInterface $entity_type, string $conjunction, array $namespaces)

Constructs this object.

Parameters

EntityTypeInterface $entity_type

The entity type definition.

string $conjunction
  • AND: all of the conditions on the query need to match.
  • OR: at least one of the conditions on the query need to match.
array $namespaces

List of potential namespaces of the classes belonging to this query.

string getEntityTypeId()

Gets the ID of the entity type for this query.

Return Value

string

$this condition($property, $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:

Parameters

$property
$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

$this

$this exists($property, $langcode = NULL)

Queries for a non-empty value on a field.

Parameters

$property
$langcode

Language code (optional).

Return Value

$this

$this notExists($property, $langcode = NULL)

Queries for an empty field.

Parameters

$property
$langcode

Language code (optional).

Return Value

$this

$this range(null $start = NULL, null $length = NULL)

No description

Parameters

null $start
null $length

Return Value

$this

The called object.

protected ConditionInterface conditionGroupFactory(string $conjunction = 'AND')

Creates an object holding a group of conditions.

See andConditionGroup() and orConditionGroup() for more.

Parameters

string $conjunction
  • AND (default): this is the equivalent of andConditionGroup().
  • OR: this is the equivalent of orConditionGroup().

Return Value

ConditionInterface

An object holding a group of conditions.

ConditionInterface 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:

Return Value

ConditionInterface

ConditionInterface 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:

Return Value

ConditionInterface

$this sort($field, string $direction = 'ASC', $langcode = NULL)

No description

Parameters

$field

Name of a field.

string $direction
$langcode

Language code (optional).

Return Value

$this

The called object.

$this count()

Makes this a count query.

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

Return Value

$this

The called object.

$this accessCheck($access_check = TRUE)

No description

Parameters

$access_check

Return Value

$this

The called object.

$this currentRevision()

Queries the current revision.

Return Value

$this

$this latestRevision()

Queries the latest revision.

The latest revision is the most recent revision of an entity. This will be either the default revision, or a pending revision if one exists and it is newer than the default.

Return Value

$this

$this allRevisions()

Queries all the revisions.

Return Value

$this

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

Enables a pager for the query.

Parameters

$limit

An integer specifying the number of elements per page. If passed a false value (FALSE, 0, NULL), the pager is disabled.

$element

An optional integer to distinguish between multiple pagers on one page. If not provided, one is automatically calculated.

Return Value

$this

The called object.

protected initializePager()

Gets the total number of results and initialize a pager for the query.

The pager can be disabled by either setting the pager limit to 0, or by setting this query to be a count query.

$this tableSort($headers)

Enables sortable tables for this query.

Parameters

$headers

An 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().

Return Value

$this

The called object.

__clone()

Makes sure that the Condition object is cloned as well.

$this addTag($tag)

Adds a tag to a query.

Tags are strings that identify a query. A query may have any number of tags. Tags are used to mark a query so that alter hooks may decide if they wish to take action. Tags should be all lower-case and contain only letters, numbers, and underscore, and start with a letter. That is, they should follow the same rules as PHP identifiers in general.

Parameters

$tag

The tag to add.

Return Value

$this

The called object.

true hasTag($tag)

Determines if a given query has a given tag.

Parameters

$tag

The tag to check.

Return Value

true

if this query has been marked with this tag, FALSE otherwise.

true hasAllTags()

Determines if a given query has all specified tags.

Each tag to check should be supplied as a separate argument.

Return Value

true

if this query has been marked with all specified tags, FALSE otherwise.

true hasAnyTag()

Determines if a given query has any specified tag.

Each tag to check should be supplied as a separate argument.

Return Value

true

if this query has been marked with at least one of the specified tags, FALSE otherwise.

$this addMetaData($key, $object)

Adds additional metadata to the query.

Often, a query may need to provide additional contextual data to alter hooks. Alter hooks may then use that information to decide if and how to take action.

Parameters

$key

The unique identifier for this piece of metadata. Must be a string that follows the same rules as any other PHP identifier.

$object

The additional data to add to the query. May be any valid PHP variable.

Return Value

$this

The called object.

The getMetaData($key)

Retrieves a given piece of metadata.

Parameters

$key

The unique identifier for the piece of metadata to retrieve.

Return Value

The

previously attached metadata object, or NULL if one doesn't exist.

aggregate($field, $function, $langcode = NULL, $alias = NULL)

{@inheritdoc}

Parameters

$field
$function
$langcode
$alias

conditionAggregate($field, $function = NULL, $value = NULL, $operator = '=', $langcode = NULL)

{@inheritdoc}

Parameters

$field
$function
$value
$operator
$langcode

sortAggregate($field, $function, $direction = 'ASC', $langcode = NULL)

{@inheritdoc}

Parameters

$field
$function
$direction
$langcode

groupBy($field, $langcode = NULL)

{@inheritdoc}

Parameters

$field
$langcode

protected string getAggregationAlias(string $field, string $function)

Generates an alias for a field and its aggregated function.

Parameters

string $field

The field name used in the alias.

string $function

The aggregation function used in the alias.

Return Value

string

The alias for the field.

static array getNamespaces($object)

Gets a list of namespaces of the ancestors of a class.

Parameters

$object

An object within a namespace.

Return Value

array

A list containing the namespace of the class, the namespace of the parent of the class and so on and so on.

static string getClass(array $namespaces, string $short_class_name)

Finds a class in a list of namespaces.

Parameters

array $namespaces

A list of namespaces.

string $short_class_name

A class name without namespace.

Return Value

string

The fully qualified name of the class.