You are here

public function Tables::addField in Drupal 9

Same name in this branch
  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()
Same name and namespace in other branches
  1. 8 core/modules/workspaces/src/EntityQuery/Tables.php \Drupal\workspaces\EntityQuery\Tables::addField()

Adds a field to a database query.

Parameters

string $field: If it doesn't contain a dot, then an entity base field name. If it contains a dot, then either field name dot field column or field name dot delta dot field column. Delta can be a numeric value or a "%delta" for any value.

string $type: Join type, can either be INNER or LEFT.

string $langcode: The language code the field values are to be queried in.

Return value

string The return value is a string containing the alias of the table, a dot and the appropriate SQL column as passed in. This allows the direct use of this in a query for a condition or sort.

Throws

\Drupal\Core\Entity\Query\QueryException If $field specifies an invalid relationship.

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