function hook_entity_query_alter
Same name in other branches
- 7.x modules/system/system.api.php \hook_entity_query_alter()
- 11.x core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_query_alter()
Alter an entity query.
Parameters
\Drupal\Core\Entity\Query\QueryInterface $query: The entity query.
See also
hook_entity_query_ENTITY_TYPE_alter()
hook_entity_query_tag__TAG_alter()
\Drupal\Core\Entity\Query\QueryInterface
Related topics
1 function implements 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 core/
modules/ field/ tests/ modules/ field_test/ field_test.module - Implements hook_entity_query_alter().
File
-
core/
lib/ Drupal/ Core/ Entity/ entity.api.php, line 2319
Code
function hook_entity_query_alter(\Drupal\Core\Entity\Query\QueryInterface $query) : void {
if ($query->hasTag('entity_reference')) {
$entityType = \Drupal::entityTypeManager()->getDefinition($query->getEntityTypeId());
$query->sort($entityType->getKey('id'), 'desc');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.