function PageContext::build

Overrides TopBarItemBase::build

File

core/modules/navigation/src/Plugin/TopBarItem/PageContext.php, line 71

Class

PageContext
Provides the Page Context top bar item.

Namespace

Drupal\navigation\Plugin\TopBarItem

Code

public function build() : array {
    $build = [
        '#cache' => [
            'contexts' => [
                'route',
            ],
        ],
    ];
    if (!($entity = $this->entityRouteHelper
        ->getContentEntityFromRoute())) {
        return $build;
    }
    $build += [
        [
            '#type' => 'component',
            '#component' => 'navigation:title',
            '#props' => [
                'icon' => 'database',
                'html_tag' => 'span',
                'modifiers' => [
                    'ellipsis',
                    'xs',
                ],
                'extra_classes' => [
                    'top-bar__title',
                ],
            ],
            '#slots' => [
                'content' => $entity->label(),
            ],
        ],
    ];
    if ($label = $this->getBadgeLabel($entity)) {
        $build += [
            '#type' => 'component',
            '#component' => 'navigation:badge',
            '#props' => [
                'status' => $this->getBadgeStatus($entity) ?? 'info',
            ],
            '#slots' => [
                'label' => $label,
            ],
        ];
    }
    return $build;
}

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