function hook_query_alter
Same name in other branches
- 7.x modules/system/system.api.php \hook_query_alter()
- 9 core/lib/Drupal/Core/Database/database.api.php \hook_query_alter()
- 8.9.x core/lib/Drupal/Core/Database/database.api.php \hook_query_alter()
- 10 core/lib/Drupal/Core/Database/database.api.php \hook_query_alter()
Perform alterations to a structured query.
Structured (aka dynamic) queries that have tags associated may be altered by any module before the query is executed.
Parameters
$query: A Query object describing the composite parts of a SQL query.
See also
node_query_node_access_alter()
AlterableInterface
Related topics
6 functions implement hook_query_alter()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- content_moderation_test_views_views_query_alter in core/
modules/ content_moderation/ tests/ modules/ content_moderation_test_views/ content_moderation_test_views.module - Implements hook_views_query_alter().
- database_test_query_alter in core/
modules/ system/ tests/ modules/ database_test/ database_test.module - Implements hook_query_alter().
- field_test_entity_query_alter in core/
modules/ field/ tests/ modules/ field_test/ field_test.module - Implements hook_entity_query_alter().
- taxonomy_test_query_alter in core/
modules/ taxonomy/ tests/ modules/ taxonomy_test/ taxonomy_test.module - Implements hook_query_alter().
- views_test_data_views_query_alter in core/
modules/ views/ tests/ modules/ views_test_data/ views_test_data.views_execution.inc - Implements hook_views_query_alter().
1 invocation of hook_query_alter()
- DefaultSelection::reAlterQuery in core/
lib/ Drupal/ Core/ Entity/ Plugin/ EntityReferenceSelection/ DefaultSelection.php - Helper method: Passes a query to the alteration system again.
File
-
core/
lib/ Drupal/ Core/ Database/ database.api.php, line 485
Code
function hook_query_alter(Drupal\Core\Database\Query\AlterableInterface $query) {
if ($query->hasTag('micro_limit')) {
$query->range(0, 2);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.