You are here

class Query in Drupal 10

Same name in this branch
  1. 10 core/modules/workspaces/src/EntityQuery/Query.php \Drupal\workspaces\EntityQuery\Query
  2. 10 core/lib/Drupal/Core/Database/Query/Query.php \Drupal\Core\Database\Query\Query
  3. 10 core/lib/Drupal/Core/Config/Entity/Query/Query.php \Drupal\Core\Config\Entity\Query\Query
  4. 10 core/lib/Drupal/Core/Entity/KeyValueStore/Query/Query.php \Drupal\Core\Entity\KeyValueStore\Query\Query
  5. 10 core/lib/Drupal/Core/Entity/Query/Sql/Query.php \Drupal\Core\Entity\Query\Sql\Query
  6. 10 core/lib/Drupal/Core/Entity/Query/Null/Query.php \Drupal\Core\Entity\Query\Null\Query
Same name and namespace in other branches
  1. 8 core/modules/workspaces/src/EntityQuery/Query.php \Drupal\workspaces\EntityQuery\Query
  2. 9 core/modules/workspaces/src/EntityQuery/Query.php \Drupal\workspaces\EntityQuery\Query

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

Hierarchy

  • class \Drupal\workspaces\EntityQuery\Query extends \Drupal\Core\Entity\Query\Sql\Query uses QueryTrait

Expanded class hierarchy of Query

8 string references to 'Query'
drupal7.php in core/modules/tracker/tests/fixtures/drupal7.php
A database agnostic dump for testing purposes.
drupal7.php in core/modules/rdf/tests/fixtures/drupal7.php
A database agnostic dump for testing purposes.
drupal7.php in core/modules/migrate_drupal/tests/fixtures/drupal7.php
A database agnostic dump for testing purposes.
PgsqlQueryFactory::get in core/modules/workspaces/src/EntityQuery/PgsqlQueryFactory.php
Instantiates an entity query for a given entity type.
QueryFactory::get in core/modules/workspaces/src/EntityQuery/QueryFactory.php
Instantiates an entity query for a given entity type.

... See full list

File

core/modules/workspaces/src/EntityQuery/Query.php, line 10

Namespace

Drupal\workspaces\EntityQuery
View source
class Query extends BaseQuery {
  use QueryTrait {
    prepare as traitPrepare;
  }

  /**
   * {@inheritdoc}
   */
  public function prepare() {
    $this
      ->traitPrepare();

    // If the prepare() method from the trait decided that we need to alter this
    // query, we need to re-define the key fields for fetchAllKeyed() as SQL
    // expressions.
    if ($this->sqlQuery
      ->getMetaData('active_workspace_id')) {
      $id_field = $this->entityType
        ->getKey('id');
      $revision_field = $this->entityType
        ->getKey('revision');

      // Since the query is against the base table, we have to take into account
      // that the revision ID might come from the workspace_association
      // relationship, and, as a consequence, the revision ID field is no longer
      // a simple SQL field but an expression.
      $this->sqlFields = [];
      $this->sqlQuery
        ->addExpression("COALESCE([workspace_association].[target_entity_revision_id], [base_table].[{$revision_field}])", $revision_field);
      $this->sqlQuery
        ->addExpression("[base_table].[{$id_field}]", $id_field);
      $this->sqlGroupBy['workspace_association.target_entity_revision_id'] = 'workspace_association.target_entity_revision_id';
      $this->sqlGroupBy["base_table.{$id_field}"] = "base_table.{$id_field}";
      $this->sqlGroupBy["base_table.{$revision_field}"] = "base_table.{$revision_field}";
    }
    return $this;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Query::prepare public function
QueryTrait::$workspaceManager protected property The workspace manager.
QueryTrait::isSimpleQuery public function
QueryTrait::prepare public function Aliased as: traitPrepare
QueryTrait::__construct public function Constructs a Query object.