$cache =
$this->cache->
get('workspace_tree'
);
if ($cache) { $this->tree =
$cache->data;
return $this->tree;
} /** @var \Drupal\workspaces\WorkspaceInterface[] $workspaces */
$workspaces =
$this->entityTypeManager->
getStorage('workspace'
)->
loadMultiple();
// First, sort everything alphabetically.
uasort($workspaces,
function DWorkspaceInterface
$a, WorkspaceInterface
$b) { assert(Inspector::
assertStringable($a->
label()) && Inspector::
assertStringable($b->
label()), 'Workspace labels are expected to be a string.'
);
return strnatcasecmp($a->
label(),
$b->
label());
});
$tree_children =
[];
foreach ($workspaces as $workspace_id =>
$workspace) { $tree_children[$workspace->parent->target_id
][] =
$workspace_id;
} // Keeps track of the parents we have to process, the last entry is used
// for the next processing step. Top-level (root) workspace use NULL as
// the parent, so we need to initialize the list with that value.