class ToolbarHandler in Rebuild Cache Access 8
Toolbar integration handler.
Hierarchy
- class \Drupal\rebuild_cache_access\ToolbarHandler implements ContainerInjectionInterface uses StringTranslationTrait
Expanded class hierarchy of ToolbarHandler
1 file declares its use of ToolbarHandler
- rebuild_cache_access.module in ./
rebuild_cache_access.module - This module adds a 'Rebuild Cache' permission and button to the toolbar.
File
- src/
ToolbarHandler.php, line 14
Namespace
Drupal\rebuild_cache_accessView source
class ToolbarHandler implements ContainerInjectionInterface {
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;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('current_user'));
}
/**
* Hook bridge.
*
* @return array
* The devel toolbar items render array.
*
* @see hook_toolbar()
*/
public function toolbar() {
$items['rebuild_cache_access'] = [
'#cache' => [
'contexts' => [
'user.permissions',
],
],
];
if ($this->account
->hasPermission('rebuild cache access')) {
$items['rebuild_cache_access'] += [
'#type' => 'toolbar_item',
'#weight' => 999,
'tab' => [
'#type' => 'link',
'#title' => $this
->t('Rebuild Cache'),
'#url' => Url::fromRoute('rebuild_cache_access.rebuild_cache'),
'#attributes' => [
'title' => $this
->t('Rebuild Cache Access'),
'class' => [
'toolbar-icon',
'toolbar-icon-rebuild-cache-access',
],
],
],
'#attached' => [
'library' => 'rebuild_cache_access/rebuild-cache-access-toolbar',
],
];
}
return $items;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
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. | |
ToolbarHandler:: |
protected | property | The current user. | |
ToolbarHandler:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
ToolbarHandler:: |
public | function | Hook bridge. | |
ToolbarHandler:: |
public | function | ToolbarHandler constructor. |