function NavigationUserBlock::build
Same name in other branches
- 10 core/modules/navigation/src/Plugin/Block/NavigationUserBlock.php \Drupal\navigation\Plugin\Block\NavigationUserBlock::build()
Overrides BlockPluginInterface::build
File
-
core/
modules/ navigation/ src/ Plugin/ Block/ NavigationUserBlock.php, line 70
Class
- NavigationUserBlock
- Defines a user navigation block.
Namespace
Drupal\navigation\Plugin\BlockCode
public function build() : array {
$menu_name = static::NAVIGATION_LINKS_MENU;
$parameters = new MenuTreeParameters();
$parameters->setMinDepth(0)
->setMaxDepth(2)
->onlyEnabledLinks();
$subtree = $this->menuTree
->load($menu_name, $parameters);
// Create a parent link that serves as a wrapper.
// If the menu is removed for any reason, this item shows a link to the
// user profile page as a fallback.
$link = MenuLinkDefault::create($this->container, [], 'navigation.user_links.user.wrapper', $this->menuLinkDefinition());
$tree = new MenuLinkTreeElement($link, TRUE, 1, FALSE, $subtree);
$manipulators = [
[
'callable' => 'menu.default_tree_manipulators:checkAccess',
],
[
'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
],
];
$tree = $this->menuTree
->transform([
$tree,
], $manipulators);
$build = $this->menuTree
->build($tree);
$build['#title'] = $this->configuration['label'];
$build += [
'#attached' => [
'library' => [
'navigation/internal.user-block',
],
],
'#attributes' => [
'data-user-block' => TRUE,
],
];
return $build;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.