function toolbar_anti_flicker_preprocess_html in Toolbar Anti-flicker 8.3
Same name and namespace in other branches
- 8 toolbar_anti_flicker.module \toolbar_anti_flicker_preprocess_html()
- 8.2 toolbar_anti_flicker.module \toolbar_anti_flicker_preprocess_html()
- 9.3.x toolbar_anti_flicker.module \toolbar_anti_flicker_preprocess_html()
Implements hook_preprocess_HOOK() for HTML document templates.
File
- ./
toolbar_anti_flicker.module, line 21
Code
function toolbar_anti_flicker_preprocess_html(&$variables) {
if (!\Drupal::currentUser()
->hasPermission('access toolbar')) {
return;
}
$orientation = \Drupal::request()->cookies
->get('toolbar');
if (version_compare(\DRUPAL::VERSION, 8.4, '<')) {
$variables['attributes']['class'][] = 'toolbar-loading';
$variables['attributes']['class'][] = 'toolbar-fixed';
}
else {
// Removing extra class from D8.4 fixes.
// It can be \Drupal\Core\Template\ArrayAccess or Array
if (is_array($variables['attributes']['class'])) {
if ($orientation == 'vertical') {
unset($variables['attributes']['class']['toolbar-horizontal']);
}
else {
unset($variables['attributes']['class']['toolbar-vertical']);
}
}
else {
if ($orientation == 'vertical') {
$variables['attributes']
->removeClass('toolbar-horizontal');
}
else {
$variables['attributes']
->removeClass('toolbar-vertical');
}
}
}
if (is_array($variables['attributes']['class'])) {
if ($orientation == 'vertical') {
$variables['attributes']['class'][] = 'toolbar-vertical';
}
else {
$variables['attributes']['class'][] = 'toolbar-horizontal';
}
}
else {
if ($orientation == 'vertical') {
$variables['attributes']
->addClass('toolbar-vertical');
}
else {
$variables['attributes']
->addClass('toolbar-horizontal');
}
}
// Remove left margin for closed Vertical mode.
$activeTab = \Drupal::request()->cookies
->get('toolbarActiveTab');
if (!empty($activeTab)) {
$variables['attributes']['class'][] = 'toolbar-tray-open';
}
elseif (version_compare(\DRUPAL::VERSION, 8.4, '>')) {
// It can be \Drupal\Core\Template\ArrayAccess or Array
if (is_array($variables['attributes']['class'])) {
unset($variables['attributes']['class']['toolbar-tray-open']);
}
else {
$variables['attributes']
->removeClass('toolbar-tray-open');
}
}
}