fortytwo_admin_toolbar.module in FortyTwo - Administration toolbar 8
Same filename and directory in other branches
Fortytwo - Administration toolbar.
File
fortytwo_admin_toolbar.moduleView source
<?php
/**
* @file
* Fortytwo - Administration toolbar.
*/
use Drupal\Core\Url;
/**
* Implements hook_preprocess_HOOK().
*/
function fortytwo_admin_toolbar_preprocess_html(&$variables) {
// Add adminimal-admin-toolbar class to the body.
if (_fortytwo_admin_toolbar_is_access()) {
$variables['attributes']['class'][] = 'fortytwo-admin-toolbar';
$config = \Drupal::service('config.factory')
->getEditable('config.fortytwo_admin_toolbar');
$profile = !empty($config
->get('color_profile')) ? $config
->get('color_profile') : 'beeblebrox';
$variables['attributes']['class'][] = 'fortytwo-admin-toolbar-' . $profile;
}
}
/**
* Implements hook_page_attachments_alter().
*/
function fortytwo_admin_toolbar_page_attachments_alter(array &$page) {
// Attaches css assets globally.
if (_fortytwo_admin_toolbar_is_access()) {
$page['#attached']['library'][] = 'fortytwo_admin_toolbar/fortytwo-admin-toolbar';
}
}
/**
* Implements hook_toolbar_alter().
*/
function fortytwo_admin_toolbar_toolbar_alter(&$items) {
// Add class to the user tab so it can be moved to the right.
if (_fortytwo_admin_toolbar_is_access()) {
$items['user']['#wrapper_attributes']['class'] = array(
'user-toolbar-tab',
);
}
}
/**
* Implements hook_toolbar().
*/
function fortytwo_admin_toolbar_toolbar() {
$items = array();
$items['size_switch'] = array(
'#type' => 'toolbar_item',
'tab' => array(
'#type' => 'link',
'#title' => t('Switch sidebar size'),
'#url' => Url::fromRoute('<front>'),
'#options' => array(
'attributes' => array(
'class' => array(
'toolbar-icon',
'toolbar-icon-switch-size',
),
),
),
),
'#weight' => -19,
);
return $items;
}
/**
* Helper function for checking user permission.
*/
function _fortytwo_admin_toolbar_is_access() {
$user = \Drupal::currentUser();
return $user
->hasPermission('access toolbar');
}
Functions
Name | Description |
---|---|
fortytwo_admin_toolbar_page_attachments_alter | Implements hook_page_attachments_alter(). |
fortytwo_admin_toolbar_preprocess_html | Implements hook_preprocess_HOOK(). |
fortytwo_admin_toolbar_toolbar | Implements hook_toolbar(). |
fortytwo_admin_toolbar_toolbar_alter | Implements hook_toolbar_alter(). |
_fortytwo_admin_toolbar_is_access | Helper function for checking user permission. |