function ToolbarLinkBuilder::renderToolbarLinks

Same name in other branches
  1. 8.9.x core/modules/user/src/ToolbarLinkBuilder.php \Drupal\user\ToolbarLinkBuilder::renderToolbarLinks()
  2. 10 core/modules/user/src/ToolbarLinkBuilder.php \Drupal\user\ToolbarLinkBuilder::renderToolbarLinks()
  3. 11.x core/modules/user/src/ToolbarLinkBuilder.php \Drupal\user\ToolbarLinkBuilder::renderToolbarLinks()

Lazy builder callback for rendering toolbar links.

Return value

array A renderable array as expected by the renderer service.

File

core/modules/user/src/ToolbarLinkBuilder.php, line 40

Class

ToolbarLinkBuilder
ToolbarLinkBuilder fills out the placeholders generated in user_toolbar().

Namespace

Drupal\user

Code

public function renderToolbarLinks() {
    $links = [
        'account' => [
            'title' => $this->t('View profile'),
            'url' => Url::fromRoute('user.page'),
            'attributes' => [
                'title' => $this->t('User account'),
            ],
        ],
        'account_edit' => [
            'title' => $this->t('Edit profile'),
            'url' => Url::fromRoute('entity.user.edit_form', [
                'user' => $this->account
                    ->id(),
            ]),
            'attributes' => [
                'title' => $this->t('Edit user account'),
            ],
        ],
        'logout' => [
            'title' => $this->t('Log out'),
            'url' => Url::fromRoute('user.logout'),
        ],
    ];
    $build = [
        '#theme' => 'links__toolbar_user',
        '#links' => $links,
        '#attributes' => [
            'class' => [
                'toolbar-menu',
            ],
        ],
        '#cache' => [
            'contexts' => [
                'user',
            ],
        ],
    ];
    return $build;
}

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