5 use Drupal\Core\Session\AccountProxyInterface;
6 use Drupal\Core\StringTranslation\StringTranslationTrait;
10 * ToolbarLinkBuilder fills out the placeholders generated in user_toolbar().
12 class ToolbarLinkBuilder {
14 use StringTranslationTrait;
19 * @var \Drupal\Core\Session\AccountProxyInterface
24 * ToolbarHandler constructor.
26 * @param \Drupal\Core\Session\AccountProxyInterface $account
29 public function __construct(AccountProxyInterface $account) {
30 $this->account = $account;
34 * Lazy builder callback for rendering toolbar links.
37 * A renderable array as expected by the renderer service.
39 public function renderToolbarLinks() {
42 'title' => $this->t('View profile'),
43 'url' => Url::fromRoute('user.page'),
45 'title' => $this->t('User account'),
49 'title' => $this->t('Edit profile'),
50 'url' => Url::fromRoute('entity.user.edit_form', ['user' => $this->account->id()]),
52 'title' => $this->t('Edit user account'),
56 'title' => $this->t('Log out'),
57 'url' => Url::fromRoute('user.logout'),
61 '#theme' => 'links__toolbar_user',
64 'class' => ['toolbar-menu'],
67 'contexts' => ['user'],
75 * Lazy builder callback for rendering the username.
78 * A renderable array as expected by the renderer service.
80 public function renderDisplayName() {
82 '#markup' => $this->account->getDisplayName(),