function QueryBase::alter

Same name in other branches
  1. 11.x core/lib/Drupal/Core/Entity/Query/QueryBase.php \Drupal\Core\Entity\Query\QueryBase::alter()

Invoke hooks to allow modules to alter the entity query.

Modules may alter all queries or only those having a particular tag. Alteration happens before the query is prepared for execution, so that the alterations then get prepared in the same way.

Return value

$this Returns the called object.

1 call to QueryBase::alter()
Query::execute in core/lib/Drupal/Core/Config/Entity/Query/Query.php

File

core/lib/Drupal/Core/Entity/Query/QueryBase.php, line 523

Class

QueryBase
The base entity query class.

Namespace

Drupal\Core\Entity\Query

Code

protected function alter() : QueryInterface {
    $hooks = [
        'entity_query',
        'entity_query_' . $this->getEntityTypeId(),
    ];
    if ($this->alterTags) {
        foreach ($this->alterTags as $tag => $value) {
            // Tags and entity type ids may well contain single underscores, and
            // 'tag' is a possible entity type id. Therefore use double underscores
            // to avoid collisions.
            $hooks[] = 'entity_query_tag__' . $tag;
            $hooks[] = 'entity_query_tag__' . $this->getEntityTypeId() . '__' . $tag;
        }
    }
    \Drupal::moduleHandler()->alter($hooks, $this);
    return $this;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.