function olivero_preprocess_html in Drupal 10
Same name and namespace in other branches
- 9 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 - Functions to support theming in the Olivero theme.
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::state()
->get('system.css_js_query_string') ?: '0';
// 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,
],
];
}