You are here

class ToolbarHandler in Rebuild Cache Access 8

Toolbar integration handler.

Hierarchy

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_access
View 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

Namesort descending Modifiers Type Description Overrides
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
ToolbarHandler::$account protected property The current user.
ToolbarHandler::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
ToolbarHandler::toolbar public function Hook bridge.
ToolbarHandler::__construct public function ToolbarHandler constructor.