function olivero_preprocess_html
Same name in other branches
- 9 core/themes/olivero/olivero.theme \olivero_preprocess_html()
- 11.x core/themes/olivero/olivero.theme \olivero_preprocess_html()
Implements hook_preprocess_HOOK() for HTML document templates.
Adds body classes if certain regions have content.
File
-
core/
themes/ olivero/ olivero.theme, line 20
Code
function olivero_preprocess_html(&$variables) {
if (theme_get_setting('mobile_menu_all_widths') === 1) {
$variables['attributes']['class'][] = 'is-always-mobile-nav';
}
// Convert custom hex to hsl so we can use the hue value
$brand_color_hex = theme_get_setting('base_primary_color') ?? '#1b9ae4';
[
$h,
$s,
$l,
] = _olivero_hex_to_hsl($brand_color_hex);
$variables['html_attributes']->setAttribute('style', "--color--primary-hue:{$h};--color--primary-saturation:{$s}%;--color--primary-lightness:{$l}");
// So fonts can be preloaded from base theme in the event Olivero is used as a subtheme.
$variables['olivero_path'] = \Drupal::request()->getBasePath() . '/' . \Drupal::service('extension.list.theme')->getPath('olivero');
$query_string = \Drupal::service('asset.query_string')->get();
// Create render array with noscript tag to output non-JavaScript
// stylesheet for primary menu.
$variables['noscript_styles'] = [
'#type' => 'html_tag',
'#noscript' => TRUE,
'#tag' => 'link',
'#attributes' => [
'rel' => 'stylesheet',
'href' => $variables['olivero_path'] . '/css/components/navigation/nav-primary-no-js.css?' . $query_string,
],
];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.