Skip to content
Snippets Groups Projects
Unverified Commit 1c607f5f authored by Lucas Hedding's avatar Lucas Hedding
Browse files

hide some un-usable operations

parent fcece3bb
No related branches found
No related tags found
1 merge request!9940Resolve #3091490 "Hide unusable workspace operations"
...@@ -56,8 +56,17 @@ class WorkspaceListBuilder extends EntityListBuilder { ...@@ -56,8 +56,17 @@ class WorkspaceListBuilder extends EntityListBuilder {
* The workspace repository service. * The workspace repository service.
* @param \Drupal\Core\Render\RendererInterface $renderer * @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer service. * 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); parent::__construct($entity_type, $storage);
$this->workspaceManager = $workspace_manager; $this->workspaceManager = $workspace_manager;
$this->workspaceRepository = $workspace_repository; $this->workspaceRepository = $workspace_repository;
...@@ -73,7 +82,8 @@ public static function createInstance(ContainerInterface $container, EntityTypeI ...@@ -73,7 +82,8 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
$container->get('entity_type.manager')->getStorage($entity_type->id()), $container->get('entity_type.manager')->getStorage($entity_type->id()),
$container->get('workspaces.manager'), $container->get('workspaces.manager'),
$container->get('workspaces.repository'), $container->get('workspaces.repository'),
$container->get('renderer') $container->get('renderer'),
$container->get('workspaces.association'),
); );
} }
...@@ -156,7 +166,7 @@ public function getDefaultOperations(EntityInterface $entity) { ...@@ -156,7 +166,7 @@ public function getDefaultOperations(EntityInterface $entity) {
]; ];
} }
if (!$entity->hasParent()) { if ($this->isPublishable($entity)) {
$operations['publish'] = [ $operations['publish'] = [
'title' => $this->t('Publish content'), 'title' => $this->t('Publish content'),
// The 'Publish' operation should be the default one for the currently // The 'Publish' operation should be the default one for the currently
...@@ -168,7 +178,7 @@ public function getDefaultOperations(EntityInterface $entity) { ...@@ -168,7 +178,7 @@ public function getDefaultOperations(EntityInterface $entity) {
), ),
]; ];
} }
else { elseif ($entity->hasParent()) {
/** @var \Drupal\workspaces\WorkspaceInterface $parent */ /** @var \Drupal\workspaces\WorkspaceInterface $parent */
$parent = $entity->parent->entity; $parent = $entity->parent->entity;
$operations['merge'] = [ $operations['merge'] = [
...@@ -399,4 +409,17 @@ protected function offCanvasRender(array &$build) { ...@@ -399,4 +409,17 @@ protected function offCanvasRender(array &$build) {
unset($build['pager']); 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;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment