function NavigationRenderer::buildTopBar

Same name in other branches
  1. 11.x core/modules/navigation/src/NavigationRenderer.php \Drupal\navigation\NavigationRenderer::buildTopBar()

Build the top bar for content entity pages.

Parameters

array $page_top: A renderable array representing the top of the page.

See also

navigation_page_top()

hook_page_top()

File

core/modules/navigation/src/NavigationRenderer.php, line 172

Class

NavigationRenderer
Handle rendering for different pieces of the navigation.

Namespace

Drupal\navigation

Code

public function buildTopBar(array &$page_top) : void {
    if (!$this->moduleHandler
        ->moduleExists('navigation_top_bar')) {
        return;
    }
    $page_top['top_bar'] = [
        '#theme' => 'top_bar',
        '#attached' => [
            'library' => [
                'navigation/internal.navigation',
            ],
        ],
        '#cache' => [
            'contexts' => [
                'url.path',
                'user.permissions',
            ],
        ],
    ];
    // Local tasks for content entities.
    if ($this->hasLocalTasks()) {
        $local_tasks = $this->getLocalTasks();
        $page_top['top_bar']['#local_tasks'] = [
            '#theme' => 'top_bar_local_tasks',
            '#local_tasks' => $local_tasks['tasks'],
        ];
        assert($local_tasks['cacheability'] instanceof CacheableMetadata);
        CacheableMetadata::createFromRenderArray($page_top['top_bar'])->addCacheableDependency($local_tasks['cacheability'])
            ->applyTo($page_top['top_bar']);
    }
}

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