Query.php in Workspace 8.2
File
src/EntityQuery/Query.php
View source
<?php
namespace Drupal\workspace\EntityQuery;
use Drupal\Core\Entity\Query\Sql\Query as BaseQuery;
class Query extends BaseQuery {
use QueryTrait {
prepare as traitPrepare;
}
protected $sqlExpressions = [];
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->sqlExpressions[$revision_field] = "COALESCE(workspace_association.target_entity_revision_id, base_table.{$revision_field})";
$this->sqlExpressions[$id_field] = "base_table.{$id_field}";
}
return $this;
}
protected function finish() {
foreach ($this->sqlExpressions as $alias => $expression) {
$this->sqlQuery
->addExpression($expression, $alias);
}
return parent::finish();
}
}
Classes
Name |
Description |
Query |
Alters entity queries to use a workspace revision instead of the default one. |