diff --git a/core/modules/workspace/src/Changes/Changes.php b/core/modules/workspace/src/Changes/Changes.php index 3ec177dd5a..6ce78537b8 100644 --- a/core/modules/workspace/src/Changes/Changes.php +++ b/core/modules/workspace/src/Changes/Changes.php @@ -35,7 +35,7 @@ class Changes implements ChangesInterface { * * @var boolean */ - protected $includeDocs = FALSE; + protected $includeEntities = FALSE; /** * The sequence ID to start including changes from. Result includes $lastSeq. @@ -58,8 +58,8 @@ public function __construct(WorkspaceInterface $workspace, EntityTypeManagerInte /** * {@inheritdoc} */ - public function includeDocs($include_docs) { - $this->includeDocs = $include_docs; + public function includeEntities($include_entities) { + $this->includeEntities = $include_entities; return $this; } @@ -84,8 +84,7 @@ public function getNormal() { foreach ($sequences as $sequence) { // Get the document. $revision = NULL; - if ($this->includeDocs == TRUE) { - /** @var \Drupal\multiversion\Entity\Storage\ContentEntityStorageInterface $storage */ + if ($this->includeEntities == TRUE) { $storage = $this->entityTypeManager->getStorage($sequence['entity_type_id']); $storage->useWorkspace($this->workspaceId); $revision = $storage->loadRevision($sequence['revision_id']); @@ -101,7 +100,7 @@ public function getNormal() { ]; // Include the document. - if ($this->includeDocs == TRUE) { + if ($this->includeEntities == TRUE) { $changes[$sequence['entity_uuid']]['doc'] = $revision; } } diff --git a/core/modules/workspace/src/Changes/ChangesFactory.php b/core/modules/workspace/src/Changes/ChangesFactory.php index 7787723dd7..5834eaf48b 100644 --- a/core/modules/workspace/src/Changes/ChangesFactory.php +++ b/core/modules/workspace/src/Changes/ChangesFactory.php @@ -10,7 +10,7 @@ * Class ChangesFactory */ class ChangesFactory implements ChangesFactoryInterface { - + /** * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ @@ -20,12 +20,12 @@ class ChangesFactory implements ChangesFactoryInterface { * @var \Drupal\workspace\Index\SequenceIndexInterface */ protected $sequenceIndex; - + /** * @var \Drupal\workspace\Changes\Changes[] */ protected $instances = []; - + /** * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */ diff --git a/core/modules/workspace/src/Changes/ChangesInterface.php b/core/modules/workspace/src/Changes/ChangesInterface.php index 4ddb356c8b..a86b069929 100644 --- a/core/modules/workspace/src/Changes/ChangesInterface.php +++ b/core/modules/workspace/src/Changes/ChangesInterface.php @@ -3,20 +3,20 @@ namespace Drupal\workspace\Changes; /** - * Define and build a changeset for a Workspace. + * Define and build a list of changes for a Workspace. */ interface ChangesInterface { /** - * Set the flag for including entities in the changeset. + * Set the flag for including entities in the list of changes. * - * @param bool $include_docs - * Whether to include entities in the changeset. + * @param bool $include_entities + * Whether to include entities in the list of changes. * * @return \Drupal\workspace\Changes\ChangesInterface * Returns $this. */ - public function includeDocs($include_docs); + public function includeEntities($include_entities); /** * Sets from what sequence number to check for changes. @@ -31,11 +31,15 @@ public function lastSeq($seq); /** * Return the changes in a 'normal' way. + * + * @return array */ public function getNormal(); /** * Return the changes with a 'longpoll'. + * + * @return array */ public function getLongpoll(); diff --git a/core/modules/workspace/src/Entity/ContentWorkspace.php b/core/modules/workspace/src/Entity/ContentWorkspace.php index 4702225336..d30fe5398c 100644 --- a/core/modules/workspace/src/Entity/ContentWorkspace.php +++ b/core/modules/workspace/src/Entity/ContentWorkspace.php @@ -55,7 +55,6 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setDescription(t('The username of the entity creator.')) ->setSetting('target_type', 'user') ->setDefaultValueCallback('Drupal\workspace\Entity\ContentWorkspace::getCurrentUserId') - ->setTranslatable(TRUE) ->setRevisionable(TRUE); $fields['workspace'] = BaseFieldDefinition::create('entity_reference') @@ -63,7 +62,6 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setDescription(t('The workspace of the referenced content.')) ->setSetting('target_type', 'workspace') ->setRequired(TRUE) - ->setTranslatable(TRUE) ->setRevisionable(TRUE) ->addConstraint('workspace', []); diff --git a/core/modules/workspace/src/EntityAccess.php b/core/modules/workspace/src/EntityAccess.php index 134e3adac5..4482894826 100644 --- a/core/modules/workspace/src/EntityAccess.php +++ b/core/modules/workspace/src/EntityAccess.php @@ -97,10 +97,9 @@ public function entityAccess(EntityInterface $entity, $operation, AccountInterfa if (empty($result)) { return AccessResult::forbidden(); } - return $this->bypassAccessResult($account); } - return AccessResult::neutral(); + return $this->bypassAccessResult($account); } /** diff --git a/core/modules/workspace/src/Negotiator/DefaultWorkspaceNegotiator.php b/core/modules/workspace/src/Negotiator/DefaultWorkspaceNegotiator.php index ab80d8cd53..f60b6342f7 100644 --- a/core/modules/workspace/src/Negotiator/DefaultWorkspaceNegotiator.php +++ b/core/modules/workspace/src/Negotiator/DefaultWorkspaceNegotiator.php @@ -10,6 +10,23 @@ class DefaultWorkspaceNegotiator extends WorkspaceNegotiatorBase { /** + * The default workspace ID. + * + * @var string + */ + protected $defaultWorkspaceId; + + /** + * Constructor. + * + * @param string $default_workspace_id + * The default workspace ID. + */ + public function __construct($default_workspace_id) { + $this->defaultWorkspaceId = $default_workspace_id; + } + + /** * {@inheritdoc} */ public function applies(Request $request) { @@ -20,7 +37,7 @@ public function applies(Request $request) { * {@inheritdoc} */ public function getWorkspaceId(Request $request) { - return $this->container->getParameter('workspace.default'); + return $this->defaultWorkspaceId; } } diff --git a/core/modules/workspace/src/Negotiator/SessionWorkspaceNegotiator.php b/core/modules/workspace/src/Negotiator/SessionWorkspaceNegotiator.php index c2ce544b2a..81f9d4c100 100644 --- a/core/modules/workspace/src/Negotiator/SessionWorkspaceNegotiator.php +++ b/core/modules/workspace/src/Negotiator/SessionWorkspaceNegotiator.php @@ -2,6 +2,7 @@ namespace Drupal\workspace\Negotiator; +use Drupal\Core\Session\AccountInterface; use Drupal\workspace\Entity\WorkspaceInterface; use Drupal\user\PrivateTempStoreFactory; use Symfony\Component\HttpFoundation\Request; @@ -12,17 +13,40 @@ class SessionWorkspaceNegotiator extends WorkspaceNegotiatorBase { /** + * The current user. + * + * @var \Drupal\Core\Session\AccountInterface + */ + protected $currentUser; + + /** + * The tempstore factory. + * * @var \Drupal\user\PrivateTempStore */ protected $tempstore; /** + * The default workspace ID. + * + * @var string + */ + protected $defaultWorkspaceId; + + /** * Constructor. * + * @param \Drupal\Core\Session\AccountInterface $current_user + * The current user. * @param \Drupal\user\PrivateTempStoreFactory $tempstore_factory + * The tempstore factory. + * @param string $default_workspace_id + * The default workspace ID. */ - public function __construct(PrivateTempStoreFactory $tempstore_factory) { + public function __construct(AccountInterface $current_user, PrivateTempStoreFactory $tempstore_factory, $default_workspace_id) { + $this->currentUser = $current_user; $this->tempstore = $tempstore_factory->get('workspace.negotiator.session'); + $this->defaultWorkspaceId = $default_workspace_id; } /** @@ -39,7 +63,7 @@ public function applies(Request $request) { */ public function getWorkspaceId(Request $request) { $workspace_id = $this->tempstore->get('active_workspace_id'); - return $workspace_id ?: $this->container->getParameter('workspace.default'); + return $workspace_id ?: $this->defaultWorkspaceId; } /** @@ -47,7 +71,7 @@ public function getWorkspaceId(Request $request) { */ public function persist(WorkspaceInterface $workspace) { $this->tempstore->set('active_workspace_id', $workspace->id()); - return TRUE; + return parent::persist($workspace); } } diff --git a/core/modules/workspace/src/Negotiator/WorkspaceNegotiatorBase.php b/core/modules/workspace/src/Negotiator/WorkspaceNegotiatorBase.php index 2b11c4025d..6ce9e0eaaf 100644 --- a/core/modules/workspace/src/Negotiator/WorkspaceNegotiatorBase.php +++ b/core/modules/workspace/src/Negotiator/WorkspaceNegotiatorBase.php @@ -2,42 +2,12 @@ namespace Drupal\workspace\Negotiator; -use Drupal\Core\Session\AccountInterface; use Drupal\workspace\Entity\WorkspaceInterface; -use Drupal\workspace\WorkspaceManagerInterface; -use Symfony\Component\DependencyInjection\ContainerAwareInterface; -use Symfony\Component\DependencyInjection\ContainerAwareTrait; /** * Class WorkspaceNegotiatorBase */ -abstract class WorkspaceNegotiatorBase implements WorkspaceNegotiatorInterface, ContainerAwareInterface { - - use ContainerAwareTrait; - - /** - * @var \Drupal\Core\Session\AccountInterface - */ - protected $currentUser; - - /** - * @var \Drupal\workspace\WorkspaceManagerInterface - */ - protected $workspaceManager; - - /** - * {@inheritdoc} - */ - public function setCurrentUser(AccountInterface $current_user) { - $this->currentUser = $current_user; - } - - /** - * {@inheritdoc} - */ - public function setWorkspaceManager(WorkspaceManagerInterface $entity_manager) { - $this->workspaceManager = $entity_manager; - } +abstract class WorkspaceNegotiatorBase implements WorkspaceNegotiatorInterface { /** * {@inheritdoc} diff --git a/core/modules/workspace/src/Negotiator/WorkspaceNegotiatorInterface.php b/core/modules/workspace/src/Negotiator/WorkspaceNegotiatorInterface.php index e5df71ee67..1d5d1db074 100644 --- a/core/modules/workspace/src/Negotiator/WorkspaceNegotiatorInterface.php +++ b/core/modules/workspace/src/Negotiator/WorkspaceNegotiatorInterface.php @@ -2,9 +2,7 @@ namespace Drupal\workspace\Negotiator; -use Drupal\Core\Session\AccountInterface; use Drupal\workspace\Entity\WorkspaceInterface; -use Drupal\workspace\WorkspaceManagerInterface; use Symfony\Component\HttpFoundation\Request; /** @@ -13,16 +11,6 @@ interface WorkspaceNegotiatorInterface { /** - * @param \Drupal\Core\Session\AccountInterface $current_user - */ - public function setCurrentUser(AccountInterface $current_user); - - /** - * @param \Drupal\workspace\WorkspaceManagerInterface $entity_manager - */ - public function setWorkspaceManager(WorkspaceManagerInterface $entity_manager); - - /** * @param \Symfony\Component\HttpFoundation\Request $request * @return bool */ diff --git a/core/modules/workspace/src/Plugin/Field/WorkspaceFieldItemList.php b/core/modules/workspace/src/Plugin/Field/WorkspaceFieldItemList.php index 7466a65fe5..5c064d08ab 100644 --- a/core/modules/workspace/src/Plugin/Field/WorkspaceFieldItemList.php +++ b/core/modules/workspace/src/Plugin/Field/WorkspaceFieldItemList.php @@ -33,6 +33,7 @@ protected function getWorkspace() { ->condition('content_entity_revision_id', $entity->getRevisionId()) ->allRevisions() ->sort('revision_id', 'DESC') + ->accessCheck(FALSE) ->execute(); $revision_to_load = key($revisions); diff --git a/core/modules/workspace/src/Replication/DefaultReplicator.php b/core/modules/workspace/src/Replication/DefaultReplicator.php index 43f15bf9f7..b1ca88af80 100644 --- a/core/modules/workspace/src/Replication/DefaultReplicator.php +++ b/core/modules/workspace/src/Replication/DefaultReplicator.php @@ -115,7 +115,7 @@ public function replicate(UpstreamInterface $source, UpstreamInterface $target) } } - $entities = []; + $entities = []; // Load each missing revision. foreach ($rev_diffs as $entity_type_id => $revs) { foreach ($revs as $rev) { diff --git a/core/modules/workspace/src/Replication/ReplicationManager.php b/core/modules/workspace/src/Replication/ReplicationManager.php index 85b7d5f8b0..88af5e360c 100644 --- a/core/modules/workspace/src/Replication/ReplicationManager.php +++ b/core/modules/workspace/src/Replication/ReplicationManager.php @@ -1,6 +1,7 @@ replicators as $replicators) { + /** @var \Drupal\workspace\Replication\ReplicationInterface $replicator */ foreach ($replicators as $replicator) { if ($replicator->applies($source, $target)) { return $replicator->replicate($source, $target); diff --git a/core/modules/workspace/src/UpstreamInterface.php b/core/modules/workspace/src/UpstreamInterface.php index f0ab1539e4..7ad6f31086 100644 --- a/core/modules/workspace/src/UpstreamInterface.php +++ b/core/modules/workspace/src/UpstreamInterface.php @@ -16,5 +16,5 @@ * The of the upstream. */ public function getLabel(); - + } diff --git a/core/modules/workspace/workspace.module b/core/modules/workspace/workspace.module index e95d4ba501..d3e97bc919 100644 --- a/core/modules/workspace/workspace.module +++ b/core/modules/workspace/workspace.module @@ -295,28 +295,38 @@ function workspace_theme($existing, $type, $theme, $path) { * Implements hook_page_bottom(). */ function workspace_page_bottom(array &$page_bottom) { - /** @var \Drupal\workspace\Entity\WorkspaceInterface $active_workspace */ - $active_workspace = \Drupal::service('workspace.manager')->getActiveWorkspace(TRUE); - $control_block = t('Current workspace: