class ToolbarLinkBuilder in Drupal 9
Same name and namespace in other branches
- 8 core/modules/user/src/ToolbarLinkBuilder.php \Drupal\user\ToolbarLinkBuilder
ToolbarLinkBuilder fills out the placeholders generated in user_toolbar().
Hierarchy
- class \Drupal\user\ToolbarLinkBuilder implements TrustedCallbackInterface uses StringTranslationTrait
Expanded class hierarchy of ToolbarLinkBuilder
1 string reference to 'ToolbarLinkBuilder'
- user.services.yml in core/
modules/ user/ user.services.yml - core/modules/user/user.services.yml
1 service uses ToolbarLinkBuilder
- user.toolbar_link_builder in core/
modules/ user/ user.services.yml - Drupal\user\ToolbarLinkBuilder
File
- core/
modules/ user/ src/ ToolbarLinkBuilder.php, line 13
Namespace
Drupal\userView source
class ToolbarLinkBuilder implements TrustedCallbackInterface {
use StringTranslationTrait;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected $account;
/**
* ToolbarHandler constructor.
*
* @param \Drupal\Core\Session\AccountProxyInterface $account
* The current user.
*/
public function __construct(AccountProxyInterface $account) {
$this->account = $account;
}
/**
* Lazy builder callback for rendering toolbar links.
*
* @return array
* A renderable array as expected by the renderer service.
*/
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;
}
/**
* Lazy builder callback for rendering the username.
*
* @return array
* A renderable array as expected by the renderer service.
*/
public function renderDisplayName() {
return [
'#markup' => $this->account
->getDisplayName(),
];
}
/**
* {@inheritdoc}
*/
public static function trustedCallbacks() {
return [
'renderToolbarLinks',
'renderDisplayName',
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
ToolbarLinkBuilder:: |
protected | property | The current user. | |
ToolbarLinkBuilder:: |
public | function | Lazy builder callback for rendering the username. | |
ToolbarLinkBuilder:: |
public | function | Lazy builder callback for rendering toolbar links. | |
ToolbarLinkBuilder:: |
public static | function |
Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface:: |
|
ToolbarLinkBuilder:: |
public | function | ToolbarHandler constructor. | |
TrustedCallbackInterface:: |
constant | Untrusted callbacks throw exceptions. | ||
TrustedCallbackInterface:: |
constant | Untrusted callbacks trigger silenced E_USER_DEPRECATION errors. | ||
TrustedCallbackInterface:: |
constant | Untrusted callbacks trigger E_USER_WARNING errors. |