function OliveroPagePreprocessHooks::preprocessHtml
Implements hook_preprocess_HOOK() for HTML document templates.
Adds body classes if certain regions have content.
Attributes
#[Hook('preprocess_html')]
File
-
core/
themes/ olivero/ src/ Hook/ OliveroPagePreprocessHooks.php, line 29
Class
- OliveroPagePreprocessHooks
- Page preprocess hooks for olivero.
Namespace
Drupal\olivero\HookCode
public function preprocessHtml(array &$variables) : void {
if ($this->themeSettingsProvider
->getSetting('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 = $this->themeSettingsProvider
->getSetting('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'] = $this->requestStack
->getCurrentRequest()
->getBasePath() . '/' . $this->themeExtensionList
->getPath('olivero');
$query_string = $this->assetQueryString
->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.