function hook_entity_query_alter

7.x system.api.php hook_entity_query_alter($query)
8.x entity.api.php hook_entity_query_alter(\Drupal\Core\Entity\Query\QueryInterface $query)

Alter or execute an EntityFieldQuery.

Parameters

EntityFieldQuery $query: An EntityFieldQuery. One of the most important properties to be changed is EntityFieldQuery::executeCallback. If this is set to an existing function, this function will get the query as its single argument and its result will be the returned as the result of EntityFieldQuery::execute(). This can be used to change the behavior of EntityFieldQuery entirely. For example, the default implementation can only deal with one field storage engine, but it is possible to write a module that can query across field storage engines. Also, the default implementation presumes entities are stored in SQL, but the execute callback could instead query any other entity storage, local or remote.

Note the $query->altered attribute which is TRUE in case the query has already been altered once. This happens with cloned queries. If there is a pager, then such a cloned query will be executed to count all elements. This query can be detected by checking for ($query->pager && $query->count), allowing the driver to return 0 from the count query and disable the pager.

Related topics

2 functions implement hook_entity_query_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

field_test_entity_query_alter in drupal/modules/field/tests/field_test.module
Implements hook_entity_query_alter().
taxonomy_entity_query_alter in drupal/modules/taxonomy/taxonomy.module
Implements hook_entity_query_alter().

File

drupal/modules/system/system.api.php, line 403
Hooks provided by Drupal core and the System module.

Code

function hook_entity_query_alter($query) {
  $query->executeCallback = 'my_module_query_callback';
}