diff --git a/core/modules/workspaces/src/WorkspaceListBuilder.php b/core/modules/workspaces/src/WorkspaceListBuilder.php index 958f6f60d7c16b1ff8abe187a463e1d8bf109ba2..b1500beaee731e53515e91612c23c2cc08eaa423 100644 --- a/core/modules/workspaces/src/WorkspaceListBuilder.php +++ b/core/modules/workspaces/src/WorkspaceListBuilder.php @@ -56,8 +56,17 @@ class WorkspaceListBuilder extends EntityListBuilder { * The workspace repository service. * @param \Drupal\Core\Render\RendererInterface $renderer * The renderer service. + * @param \Drupal\workspaces\WorkspaceAssociationInterface $workspace_association + * The workspace association service. */ - public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, WorkspaceManagerInterface $workspace_manager, WorkspaceRepositoryInterface $workspace_repository, RendererInterface $renderer) { + public function __construct( + EntityTypeInterface $entity_type, + EntityStorageInterface $storage, + WorkspaceManagerInterface $workspace_manager, + WorkspaceRepositoryInterface $workspace_repository, + RendererInterface $renderer, + protected WorkspaceAssociationInterface $workspaceAssociation, + ) { parent::__construct($entity_type, $storage); $this->workspaceManager = $workspace_manager; $this->workspaceRepository = $workspace_repository; @@ -73,7 +82,8 @@ public static function createInstance(ContainerInterface $container, EntityTypeI $container->get('entity_type.manager')->getStorage($entity_type->id()), $container->get('workspaces.manager'), $container->get('workspaces.repository'), - $container->get('renderer') + $container->get('renderer'), + $container->get('workspaces.association'), ); } @@ -156,7 +166,7 @@ public function getDefaultOperations(EntityInterface $entity) { ]; } - if (!$entity->hasParent()) { + if ($this->isPublishable($entity)) { $operations['publish'] = [ 'title' => $this->t('Publish content'), // The 'Publish' operation should be the default one for the currently @@ -168,7 +178,7 @@ public function getDefaultOperations(EntityInterface $entity) { ), ]; } - else { + elseif ($entity->hasParent()) { /** @var \Drupal\workspaces\WorkspaceInterface $parent */ $parent = $entity->parent->entity; $operations['merge'] = [ @@ -399,4 +409,17 @@ protected function offCanvasRender(array &$build) { unset($build['pager']); } + /** + * Determine if an workspace should be publishable. + * + * @param \Drupal\workspaces\WorkspaceInterface $workspace + * + * @return bool + */ + protected function isPublishable(WorkspaceInterface $workspace): bool { + return !$workspace->hasParent() && + $this->workspaceAssociation->getTrackedEntities($workspace->id()) !== [] && + $this->storage->getQuery()->condition('parent', $workspace->id())->accessCheck(FALSE)->count()->execute() === 0; + } + }