function PreprocessHooks::html

Same name and namespace in other branches
  1. main core/themes/admin/src/Hook/PreprocessHooks.php \Drupal\admin\Hook\PreprocessHooks::html()

Implements hook_preprocess_HOOK() for HTML.

Attributes

#[Hook('preprocess_html')]

File

core/themes/admin/src/Hook/PreprocessHooks.php, line 601

Class

PreprocessHooks
Provides preprocess implementations.

Namespace

Drupal\admin\Hook

Code

public function html(array &$variables) : void {
  // Check if IMCE is active.
  if (isset($variables['attributes']['class']) && in_array('imce-page', $variables['attributes']['class'], TRUE)) {
    return;
  }
  // Get theme settings.
  $settings = Settings::getInstance();
  // Old way to set accent color.
  $variables['html_attributes']['data-gin-accent'] = $settings->get('preset_accent_color');
  // New way to set accent color.
  $accent_colors = Helper::accentColors();
  $preset = $settings->get('preset_accent_color');
  $accent_color = '';
  if ($preset === 'custom' && $settings->get('accent_color')) {
    $accent_color = $settings->get('accent_color');
  }
  elseif (isset($accent_colors[$preset]['hex'])) {
    $accent_color = $accent_colors[$preset]['hex'];
  }
  if ($accent_color) {
    $variables['html_attributes']['style'] = '--accent-base: ' . $accent_color . ';';
  }
  // Set focus color.
  $variables['html_attributes']['data-gin-focus'] = $settings->get('preset_focus_color');
  // High contrast mode.
  if ($settings->get('high_contrast_mode')) {
    $variables['html_attributes']['class'][] = 'gin--high-contrast-mode';
  }
  // Set layout density.
  $variables['html_attributes']['data-gin-layout-density'] = $settings->get('layout_density');
  // Edit form? Use the new admin Edit form layout.
  if (Helper::isContentForm()) {
    $variables['attributes']['class'][] = 'gin--edit-form';
  }
  // Only add toolbar/navigation class if user has permission.
  if (!$this->currentUser
    ->hasPermission('access toolbar') && !$this->currentUser
    ->hasPermission('access navigation')) {
    return;
  }
  // Check if Navigation module is active.
  if ($this->moduleHandler
    ->moduleExists('navigation')) {
    $variables['attributes']['class'][] = 'gin--navigation';
  }
  else {
    // Set toolbar class.
    $variables['attributes']['class'][] = 'gin--toolbar';
  }
}

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