You are here

function gin_toolbar_page_attachments_alter in Gin Toolbar 8

Implements hook_preprocess_HOOK() for page_attachments.

File

./gin_toolbar.module, line 52
gin_toolbar.module

Code

function gin_toolbar_page_attachments_alter(&$page) {

  // 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');

  // Attach the init script.
  $page['#attached']['library'][] = 'gin/gin_init';
  if ($toolbar === 'classic') {

    // Attach the classic toolbar styles.
    $page['#attached']['library'][] = 'gin/gin_classic_toolbar';
  }
  elseif ($toolbar === 'horizontal') {

    // Attach the horizontal toolbar styles.
    $page['#attached']['library'][] = 'gin/gin_horizontal_toolbar';
  }
  else {

    // Attach toolbar styles.
    $page['#attached']['library'][] = 'gin/gin_toolbar';
  }

  // Attach accent overrides CSS.
  $page['#attached']['library'][] = 'gin/gin_accent';

  // Add library for dialog.
  $page['#attached']['library'][] = 'gin/gin_dialog';
  $page['#attached']['library'][] = 'claro/claro.drupal.dialog';

  // Expose settings to JS.
  $page['#attached']['drupalSettings']['gin']['darkmode'] = $settings
    ->get('enable_darkmode');
  $page['#attached']['drupalSettings']['gin']['darkmode_class'] = 'gin--dark-mode';
  $page['#attached']['drupalSettings']['gin']['preset_accent_color'] = $settings
    ->get('preset_accent_color');
  $page['#attached']['drupalSettings']['gin']['accent_color'] = $settings
    ->get('accent_color');
  $page['#attached']['drupalSettings']['gin']['preset_focus_color'] = $settings
    ->getDefault('preset_focus_color');
  $page['#attached']['drupalSettings']['gin']['focus_color'] = $settings
    ->getDefault('focus_color');
  $page['#attached']['drupalSettings']['gin']['highcontrastmode'] = $settings
    ->get('high_contrast_mode');
  $page['#attached']['drupalSettings']['gin']['highcontrastmode_class'] = 'gin--high-contrast-mode';
}