You are here

function admin_toolbar_search_toolbar_alter in Admin Toolbar 8.2

Same name and namespace in other branches
  1. 3.x admin_toolbar_search/admin_toolbar_search.module \admin_toolbar_search_toolbar_alter()

Implements hook_toolbar_alter().

File

admin_toolbar_search/admin_toolbar_search.module, line 29
Functionality for search of Admin Toolbar.

Code

function admin_toolbar_search_toolbar_alter(&$items) {
  if (!\Drupal::currentUser()
    ->hasPermission('use admin toolbar search')) {
    return;
  }
  $admin_toolbar_tools_enabled = \Drupal::service('module_handler')
    ->moduleExists('admin_toolbar_tools');
  $items['administration_search'] = [
    "#type" => "toolbar_item",
    '#weight' => 100,
    'tab' => [
      'search' => [
        '#type' => 'textfield',
        '#size' => 30,
        '#attributes' => [
          'id' => 'admin-toolbar-search-input',
          'aria-labelledby' => 'toolbar-item-administration-search',
          'placeholder' => new TranslatableMarkup('Admin Toolbar quick search'),
        ],
      ],
    ],
    '#attached' => [
      'library' => [
        'admin_toolbar_search/search',
      ],
      'drupalSettings' => [
        'adminToolbarSearch' => [
          'loadExtraLinks' => $admin_toolbar_tools_enabled,
        ],
      ],
    ],
    '#wrapper_attributes' => [
      'id' => 'admin-toolbar-search-tab',
    ],
    '#cache' => [
      'contexts' => [
        'user.permissions',
      ],
    ],
  ];
}