1 entity.api.php | hook_entity_query_alter($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
File
- core/
modules/ entity/ entity.api.php, line 353 - Hooks provided by the Entity module.
Code
function hook_entity_query_alter($query) {
$query->executeCallback = 'my_module_query_callback';
}