You are here

function seeds_toolbar_toolbar_alter in Seeds Toolbar 8

Implements hook_toolbar_alter().

File

./seeds_toolbar.module, line 191
Contains seeds_toolbar.module.

Code

function seeds_toolbar_toolbar_alter(&$items) {

  // Convert the administration link to a button tag.
  $items["administration"]["tab"]['#type'] = 'html_tag';
  $items["administration"]["tab"]['#tag'] = 'button';
  unset($items["administration"]["tab"]['#url']);

  // Add trigger class to responsive reviews.
  if (\Drupal::service('router.admin_context')
    ->isAdminRoute()) {

    // Remove responsive preview from backend, it causes weird problems.
    if (isset($items['responsive_preview'])) {
      unset($items['responsive_preview']);
    }
  }
  else {

    // Remove "back to site" in front end.
    unset($items['home']);
    if (isset($items['responsive_preview'])) {
      $items['responsive_preview']['tab']['trigger']['#attributes']['class'][] = 'trigger';
    }
  }

  // 'Masquerade' Integration.
  if (isset($items['masquerade_switch_back'])) {
    $items['masquerade_switch_back']['tab']['#attributes']['class'][] = 'toolbar-icon-masquerade';
  }

  // 'Admin Toolbar' Search Integration
  if (\Drupal::moduleHandler()
    ->moduleExists('admin_toolbar_search') && \Drupal::currentUser()
    ->hasPermission('use admin toolbar search')) {
    $items['administration_search']['tab'] = [
      '#type' => 'link',
      '#title' => t('Search'),
      '#url' => URL::fromRoute('system.admin'),
      '#attributes' => [
        'class' => [
          'toolbar-icon',
        ],
      ],
    ];
    $items['administration_search']['tray'] = [
      'search' => [
        '#title' => 'Search',
        '#type' => 'textfield',
        '#size' => 60,
        '#attributes' => [
          'id' => 'admin-toolbar-search-input',
          'aria-labelledby' => 'toolbar-item-administration-search',
        ],
      ],
    ];
  }

  // Order the tabs if they exist.
  $first_tabs = [
    'home',
    'seeds_logo',
    'administration',
    'seeds_add',
    'shortcuts',
    'coffee',
    'seeds_support',
    'contextual',
    'devel',
    'masquerade_switch_back',
  ];
  $items = \Drupal::service('seeds_toolbar.manager')
    ->sortTabs($items, $first_tabs);
}