You are here

public function Tables::addField in Drupal 10

Same name in this branch
  1. 10 core/modules/workspaces/src/EntityQuery/Tables.php \Drupal\workspaces\EntityQuery\Tables::addField()
  2. 10 core/lib/Drupal/Core/Entity/Query/Sql/Tables.php \Drupal\Core\Entity\Query\Sql\Tables::addField()
Same name and namespace in other branches
  1. 8 core/modules/workspaces/src/EntityQuery/Tables.php \Drupal\workspaces\EntityQuery\Tables::addField()
  2. 9 core/modules/workspaces/src/EntityQuery/Tables.php \Drupal\workspaces\EntityQuery\Tables::addField()

File

core/modules/workspaces/src/EntityQuery/Tables.php, line 60

Class

Tables
Alters entity queries to use a workspace revision instead of the default one.

Namespace

Drupal\workspaces\EntityQuery

Code

public function addField($field, $type, $langcode) {

  // The parent method uses shared and dedicated revision tables only when the
  // entity query is instructed to query all revisions. However, if we are
  // looking for workspace-specific revisions, we have to force the parent
  // method to always pick the revision tables if the field being queried is
  // revisionable.
  if ($this->sqlQuery
    ->getMetaData('active_workspace_id')) {
    $previous_all_revisions = $this->sqlQuery
      ->getMetaData('all_revisions');
    $this->sqlQuery
      ->addMetaData('all_revisions', TRUE);
  }
  $alias = parent::addField($field, $type, $langcode);

  // Restore the 'all_revisions' metadata because we don't want to interfere
  // with the rest of the query.
  if (isset($previous_all_revisions)) {
    $this->sqlQuery
      ->addMetaData('all_revisions', $previous_all_revisions);
  }
  return $alias;
}