Query.php in Drupal 8
File
core/modules/workspaces/src/EntityQuery/Query.php
View source
<?php
namespace Drupal\workspaces\EntityQuery;
use Drupal\Core\Entity\Query\Sql\Query as BaseQuery;
class Query extends BaseQuery {
use QueryTrait {
prepare as traitPrepare;
}
public function prepare() {
$this
->traitPrepare();
if ($this->sqlQuery
->getMetaData('active_workspace_id')) {
$id_field = $this->entityType
->getKey('id');
$revision_field = $this->entityType
->getKey('revision');
$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;
}
}
Classes
Name |
Description |
Query |
Alters entity queries to use a workspace revision instead of the default one. |