You are here

function gin_toolbar_preprocess_html in Gin Toolbar 8

Implements hook_preprocess_HOOK() for html.

File

./gin_toolbar.module, line 16
gin_toolbar.module

Code

function gin_toolbar_preprocess_html(&$variables) {

  // Are we relevant?
  if (!_gin_toolbar_gin_is_active()) {
    return;
  }

  // Get theme settings.

  /** @var \Drupal\gin\GinSettings $settings */
  $settings = \Drupal::classResolver(GinSettings::class);
  $toolbar = $settings
    ->get('classic_toolbar');

  // Check if darkmode is enabled.
  if ($settings
    ->get('enable_darkmode')) {
    $variables['attributes']['class'][] = 'gin--dark-mode';
  }

  // Set accent color.
  $variables['attributes']['data-gin-accent'] = $settings
    ->get('preset_accent_color');

  // High contrast mode.
  if ($settings
    ->get('high_contrast_mode')) {
    $variables['attributes']['class'][] = 'gin--high-contrast-mode';
  }

  // Only add gin--classic-toolbar class if user has permission.
  if (!\Drupal::currentUser()
    ->hasPermission('access toolbar')) {
    return;
  }

  // Set toolbar.
  $variables['attributes']['class'][] = 'gin--' . $toolbar . '-toolbar';
}