function Tables::addField

Same name in this branch
  1. 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. 9 core/modules/workspaces/src/EntityQuery/Tables.php \Drupal\workspaces\EntityQuery\Tables::addField()
  2. 9 core/lib/Drupal/Core/Entity/Query/Sql/Tables.php \Drupal\Core\Entity\Query\Sql\Tables::addField()
  3. 8.9.x core/modules/workspaces/src/EntityQuery/Tables.php \Drupal\workspaces\EntityQuery\Tables::addField()
  4. 8.9.x core/lib/Drupal/Core/Entity/Query/Sql/Tables.php \Drupal\Core\Entity\Query\Sql\Tables::addField()
  5. 11.x core/modules/workspaces/src/EntityQuery/Tables.php \Drupal\workspaces\EntityQuery\Tables::addField()
  6. 11.x core/lib/Drupal/Core/Entity/Query/Sql/Tables.php \Drupal\Core\Entity\Query\Sql\Tables::addField()

Overrides 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;
}

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