You are here

function moderation_dashboard_toolbar_alter in Moderation Dashboard 8

Same name and namespace in other branches
  1. 2.0.x moderation_dashboard.module \moderation_dashboard_toolbar_alter()

Implements hook_toolbar_alter().

File

./moderation_dashboard.module, line 62
Contains hooks for the moderation_dashboard module.

Code

function moderation_dashboard_toolbar_alter(&$items) {
  $user = \Drupal::currentUser();
  if (isset($items['user']) && $user
    ->hasPermission('use moderation dashboard')) {
    $items['user']['tray']['moderation_dashboard'] = [
      '#theme' => 'links__toolbar_user',
      '#links' => [
        'moderation_dashboard_link' => [
          'title' => t('Moderation Dashboard'),
          'url' => Url::fromRoute('page_manager.page_view_moderation_dashboard_moderation_dashboard-panels_variant-0', [
            'user' => $user
              ->id(),
          ]),
          'attributes' => [
            'title' => t('View the Moderation Dashboard page'),
          ],
        ],
      ],
      '#attributes' => [
        'class' => [
          'toolbar-menu',
        ],
      ],
      '#cache' => [
        'contexts' => [
          'user.permissions',
        ],
      ],
    ];
  }
  return $items;
}