function NavigationMenuBlock::build

Same name in other branches
  1. 10 core/modules/navigation/src/Plugin/Block/NavigationMenuBlock.php \Drupal\navigation\Plugin\Block\NavigationMenuBlock::build()

Overrides SystemMenuBlock::build

File

core/modules/navigation/src/Plugin/Block/NavigationMenuBlock.php, line 76

Class

NavigationMenuBlock
Provides a generic menu navigation block.

Namespace

Drupal\navigation\Plugin\Block

Code

public function build() : array {
    $menu_name = $this->getDerivativeId();
    $level = $this->configuration['level'];
    $depth = $this->configuration['depth'];
    $parameters = new MenuTreeParameters();
    $parameters->setMinDepth($level)
        ->setMaxDepth(min($level + $depth, $this->menuTree
        ->maxDepth()))
        ->onlyEnabledLinks();
    $tree = $this->menuTree
        ->load($menu_name, $parameters);
    $manipulators = [
        [
            'callable' => 'menu.default_tree_manipulators:checkAccess',
        ],
        [
            'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
        ],
    ];
    $tree = $this->menuTree
        ->transform($tree, $manipulators);
    $build = $this->menuTree
        ->build($tree);
    if (!empty($build)) {
        $build['#title'] = $this->configuration['label'];
    }
    return $build;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.