Chris@17: workspaceManager = $workspace_manager; Chris@17: } Chris@17: Chris@17: /** Chris@17: * {@inheritdoc} Chris@17: */ Chris@17: public function prepare() { Chris@17: parent::prepare(); Chris@17: Chris@17: // Do not alter entity revision queries. Chris@17: // @todo How about queries for the latest revision? Should we alter them to Chris@17: // look for the latest workspace-specific revision? Chris@17: if ($this->allRevisions) { Chris@17: return $this; Chris@17: } Chris@17: Chris@17: // Only alter the query if the active workspace is not the default one and Chris@17: // the entity type is supported. Chris@17: $active_workspace = $this->workspaceManager->getActiveWorkspace(); Chris@17: if (!$active_workspace->isDefaultWorkspace() && $this->workspaceManager->isEntityTypeSupported($this->entityType)) { Chris@17: $this->sqlQuery->addMetaData('active_workspace_id', $active_workspace->id()); Chris@17: $this->sqlQuery->addMetaData('simple_query', FALSE); Chris@17: Chris@17: // LEFT JOIN 'workspace_association' to the base table of the query so we Chris@17: // can properly include live content along with a possible workspace Chris@17: // revision. Chris@17: $id_field = $this->entityType->getKey('id'); Chris@17: $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()}'"); Chris@17: } Chris@17: Chris@17: return $this; Chris@17: } Chris@17: Chris@18: /** Chris@18: * {@inheritdoc} Chris@18: */ Chris@18: public function isSimpleQuery() { Chris@18: // We declare that this is not a simple query in Chris@18: // \Drupal\workspaces\EntityQuery\QueryTrait::prepare(), but that's not Chris@18: // enough because the parent method can return TRUE in some circumstances. Chris@18: if ($this->sqlQuery->getMetaData('active_workspace_id')) { Chris@18: return FALSE; Chris@18: } Chris@18: Chris@18: return parent::isSimpleQuery(); Chris@18: } Chris@18: Chris@17: }