W3cubDocs

/Drupal 8

function hook_query_alter

hook_query_alter(Drupal\Core\Database\Query\AlterableInterface $query)

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

hook_query_TAG_alter()

node_query_node_access_alter()

AlterableInterface

SelectInterface

Related topics

Database abstraction layer
Allow the use of different database servers using the same code base.
Hooks
Define functions that alter the behavior of Drupal core.

File

core/lib/Drupal/Core/Database/database.api.php, line 403
Hooks related to the Database system and the Schema API.

Code

function hook_query_alter(Drupal\Core\Database\Query\AlterableInterface $query) {
  if ($query->hasTag('micro_limit')) {
    $query->range(0, 2);
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Database!database.api.php/function/hook_query_alter/8.1.x