You are here

protected function DefaultSelection::reAlterQuery in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection::reAlterQuery()
  2. 10 core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection::reAlterQuery()

Helper method: Passes a query to the alteration system again.

This allows Entity Reference to add a tag to an existing query so it can ask access control mechanisms to alter it again.

1 call to DefaultSelection::reAlterQuery()
CommentSelection::entityQueryAlter in core/modules/comment/src/Plugin/EntityReferenceSelection/CommentSelection.php
Allows the selection to alter the SelectQuery generated by EntityFieldQuery.

File

core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php, line 484

Class

DefaultSelection
Default plugin implementation of the Entity Reference Selection plugin.

Namespace

Drupal\Core\Entity\Plugin\EntityReferenceSelection

Code

protected function reAlterQuery(AlterableInterface $query, $tag, $base_table) {

  // Save the old tags and metadata.
  // For some reason, those are public.
  $old_tags = $query->alterTags;
  $old_metadata = $query->alterMetaData;
  $query->alterTags = [
    $tag => TRUE,
  ];
  $query->alterMetaData['base_table'] = $base_table;
  $this->moduleHandler
    ->alter([
    'query',
    'query_' . $tag,
  ], $query);

  // Restore the tags and metadata.
  $query->alterTags = $old_tags;
  $query->alterMetaData = $old_metadata;
}