function settings_tray_toolbar_alter
Same name in other branches
- 9 core/modules/settings_tray/settings_tray.module \settings_tray_toolbar_alter()
- 8.9.x core/modules/settings_tray/settings_tray.module \settings_tray_toolbar_alter()
- 11.x core/modules/settings_tray/settings_tray.module \settings_tray_toolbar_alter()
Implements hook_toolbar_alter().
Alters the 'contextual' toolbar tab if it exists (meaning the user is allowed to use contextual links) and if they can administer blocks.
@todo Remove the "administer blocks" requirement in https://www.drupal.org/node/2822965.
See also
File
-
core/
modules/ settings_tray/ settings_tray.module, line 142
Code
function settings_tray_toolbar_alter(&$items) {
$items['contextual']['#cache']['contexts'][] = 'user.permissions';
if (isset($items['contextual']['tab']) && \Drupal::currentUser()->hasPermission('administer blocks')) {
$items['contextual']['#weight'] = -1000;
$items['contextual']['#attached']['library'][] = 'settings_tray/drupal.settings_tray';
$items['contextual']['tab']['#attributes']['data-drupal-settingstray'] = 'toggle';
// Set a class on items to mark whether they should be active in edit mode.
// @todo Create a dynamic method for modules to set their own items.
// https://www.drupal.org/node/2784589.
$edit_mode_items = [
'contextual',
];
foreach ($items as $key => $item) {
if (!in_array($key, $edit_mode_items) && (!isset($items[$key]['#wrapper_attributes']['class']) || !in_array('hidden', $items[$key]['#wrapper_attributes']['class']))) {
$items[$key]['#wrapper_attributes']['class'][] = 'edit-mode-inactive';
}
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.