function WorkspacesMenuTreeStorage::loadLinks
Same name in other branches
- 11.x core/modules/workspaces/src/WorkspacesMenuTreeStorage.php \Drupal\workspaces\WorkspacesMenuTreeStorage::loadLinks()
Overrides MenuTreeStorage::loadLinks
File
-
core/
modules/ workspaces/ src/ WorkspacesMenuTreeStorage.php, line 67
Class
- WorkspacesMenuTreeStorage
- Overrides the default menu storage to provide workspace-specific menu links.
Namespace
Drupal\workspacesCode
protected function loadLinks($menu_name, MenuTreeParameters $parameters) {
$links = parent::loadLinks($menu_name, $parameters);
// Replace the menu link plugin definitions with workspace-specific ones.
if ($active_workspace = $this->workspaceManager
->getActiveWorkspace()) {
$tracked_revisions = $this->workspaceAssociation
->getTrackedEntities($active_workspace->id());
if (isset($tracked_revisions['menu_link_content'])) {
/** @var \Drupal\menu_link_content\MenuLinkContentInterface[] $workspace_revisions */
$workspace_revisions = $this->entityTypeManager
->getStorage('menu_link_content')
->loadMultipleRevisions(array_keys($tracked_revisions['menu_link_content']));
foreach ($workspace_revisions as $workspace_revision) {
if (isset($links[$workspace_revision->getPluginId()])) {
$pending_plugin_definition = $workspace_revision->getPluginDefinition();
$links[$workspace_revision->getPluginId()] = [
'title' => serialize($pending_plugin_definition['title']),
'description' => serialize($pending_plugin_definition['description']),
'enabled' => (string) $pending_plugin_definition['enabled'],
'url' => $pending_plugin_definition['url'],
'route_name' => $pending_plugin_definition['route_name'],
'route_parameters' => serialize($pending_plugin_definition['route_parameters']),
'options' => serialize($pending_plugin_definition['options']),
] + $links[$workspace_revision->getPluginId()];
}
}
}
}
return $links;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.