Skip to content
Snippets Groups Projects

Resolve #3091490 "Hide unusable workspace operations"

All threads resolved!
1 file
+ 26
4
Compare changes
  • Side-by-side
  • Inline
@@ -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'] = [
@@ -407,4 +417,16 @@ 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()) !== [];
}
}
Loading