Mercurial > hg > isophonics-drupal-site
comparison core/modules/user/src/ToolbarLinkBuilder.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\user; | |
4 | |
5 use Drupal\Core\Session\AccountProxyInterface; | |
6 use Drupal\Core\StringTranslation\StringTranslationTrait; | |
7 use Drupal\Core\Url; | |
8 | |
9 /** | |
10 * ToolbarLinkBuilder fills out the placeholders generated in user_toolbar(). | |
11 */ | |
12 class ToolbarLinkBuilder { | |
13 | |
14 use StringTranslationTrait; | |
15 | |
16 /** | |
17 * The current user. | |
18 * | |
19 * @var \Drupal\Core\Session\AccountProxyInterface | |
20 */ | |
21 protected $account; | |
22 | |
23 /** | |
24 * ToolbarHandler constructor. | |
25 * | |
26 * @param \Drupal\Core\Session\AccountProxyInterface $account | |
27 * The current user. | |
28 */ | |
29 public function __construct(AccountProxyInterface $account) { | |
30 $this->account = $account; | |
31 } | |
32 | |
33 /** | |
34 * Lazy builder callback for rendering toolbar links. | |
35 * | |
36 * @return array | |
37 * A renderable array as expected by the renderer service. | |
38 */ | |
39 public function renderToolbarLinks() { | |
40 $links = [ | |
41 'account' => [ | |
42 'title' => $this->t('View profile'), | |
43 'url' => Url::fromRoute('user.page'), | |
44 'attributes' => [ | |
45 'title' => $this->t('User account'), | |
46 ], | |
47 ], | |
48 'account_edit' => [ | |
49 'title' => $this->t('Edit profile'), | |
50 'url' => Url::fromRoute('entity.user.edit_form', ['user' => $this->account->id()]), | |
51 'attributes' => [ | |
52 'title' => $this->t('Edit user account'), | |
53 ], | |
54 ], | |
55 'logout' => [ | |
56 'title' => $this->t('Log out'), | |
57 'url' => Url::fromRoute('user.logout'), | |
58 ], | |
59 ]; | |
60 $build = [ | |
61 '#theme' => 'links__toolbar_user', | |
62 '#links' => $links, | |
63 '#attributes' => [ | |
64 'class' => ['toolbar-menu'], | |
65 ], | |
66 '#cache' => [ | |
67 'contexts' => ['user'], | |
68 ], | |
69 ]; | |
70 | |
71 return $build; | |
72 } | |
73 | |
74 /** | |
75 * Lazy builder callback for rendering the username. | |
76 * | |
77 * @return array | |
78 * A renderable array as expected by the renderer service. | |
79 */ | |
80 public function renderDisplayName() { | |
81 return [ | |
82 '#markup' => $this->account->getDisplayName(), | |
83 ]; | |
84 } | |
85 | |
86 } |