Same filename and directory in other branches
- 8.9.x core/modules/workspaces/src/EntityQuery/QueryTrait.php
- 9 core/modules/workspaces/src/EntityQuery/QueryTrait.php
Namespace
Drupal\workspaces\EntityQuery
File
core/modules/workspaces/src/EntityQuery/QueryTrait.php
View source
<?php
namespace Drupal\workspaces\EntityQuery;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\workspaces\WorkspaceInformationInterface;
use Drupal\workspaces\WorkspaceManagerInterface;
trait QueryTrait {
protected $workspaceManager;
protected $workspaceInfo;
public function __construct(EntityTypeInterface $entity_type, $conjunction, Connection $connection, array $namespaces, WorkspaceManagerInterface $workspace_manager, WorkspaceInformationInterface $workspace_information) {
parent::__construct($entity_type, $conjunction, $connection, $namespaces);
$this->workspaceManager = $workspace_manager;
$this->workspaceInfo = $workspace_information;
}
public function prepare() {
parent::prepare();
if ($this->allRevisions) {
return $this;
}
if ($this->workspaceInfo
->isEntityTypeSupported($this->entityType) && $this->workspaceManager
->hasActiveWorkspace()) {
$active_workspace = $this->workspaceManager
->getActiveWorkspace();
$this->sqlQuery
->addMetaData('active_workspace_id', $active_workspace
->id());
$this->sqlQuery
->addMetaData('simple_query', FALSE);
$id_field = $this->entityType
->getKey('id');
$this->sqlQuery
->leftJoin('workspace_association', 'workspace_association', "[%alias].[target_entity_type_id] = '{$this->entityTypeId}' AND [%alias].[target_entity_id] = [base_table].[{$id_field}] AND [%alias].[workspace] = '{$active_workspace->id()}'");
}
return $this;
}
public function isSimpleQuery() {
if ($this->sqlQuery
->getMetaData('active_workspace_id')) {
return FALSE;
}
return parent::isSimpleQuery();
}
}
Traits
Name |
Description |
QueryTrait |
Provides workspaces-specific helpers for altering entity queries. |