function olivero_preprocess_html

Same name and namespace in other branches
  1. 10 core/themes/olivero/olivero.theme \olivero_preprocess_html()
  2. 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';
    }
    // 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,
        ],
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.