function TopBar::preRenderTopBar

Builds the TopBar as a structured array ready for rendering.

Since building the TopBar takes some time, it is done just prior to rendering to ensure that it is built only if it will be displayed.

Parameters

array $element: A renderable array.

Return value

array A renderable array.

See also

navigation_page_top()

File

core/modules/navigation/src/Element/TopBar.php, line 50

Class

TopBar
Provides a render element for the default Drupal toolbar.

Namespace

Drupal\navigation\Element

Code

public static function preRenderTopBar($element) : array {
    $top_bar_item_manager = static::topBarItemManager();
    // Group the items by region.
    foreach (TopBarRegion::cases() as $region) {
        $items = $top_bar_item_manager->getRenderedTopBarItemsByRegion($region);
        $element = array_merge($element, [
            $region->value => $items,
        ]);
    }
    return $element;
}

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