You are here

public function ToolbarLinkBuilder::renderToolbarLinks in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/user/src/ToolbarLinkBuilder.php \Drupal\user\ToolbarLinkBuilder::renderToolbarLinks()
  2. 9 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;
}