You are here

function toolbar_themes_preprocess_toolbar_themes__base_toolbar in Toolbar Themes 8

Implements hook_preprocess_HOOK(). Preprocess variables for the base theme.

Parameters

$variables:

File

./toolbar_themes.module, line 309

Code

function toolbar_themes_preprocess_toolbar_themes__base_toolbar(&$variables) {
  $config = \Drupal::config('toolbar_themes.settings');
  $path = base_path() . drupal_get_path('module', 'toolbar_themes');

  // Icons.
  $variables['show_icons'] = $config
    ->get('icons');
  if ($variables['show_icons'] === 1) {
    $icons_path = $variables['base_theme']['path'] . '/' . $variables['base_theme']['icons'];
    if (!empty($icons_path)) {
      $grunticon_loader = [
        '#type' => 'html_tag',
        '#tag' => 'script',
        '#attributes' => [
          'src' => $path . '/' . $icons_path . '/grunticon.loader.js',
        ],
      ];
      $variables['#attached']['html_head'][] = [
        $grunticon_loader,
        'grunticon_loader',
      ];
      $grunticon_fallback = [
        '#type' => 'html_tag',
        '#tag' => 'link',
        '#noscript' => TRUE,
        '#attributes' => [
          'href' => $path . '/' . $icons_path . '/icons.fallback.css',
          'rel' => 'stylesheet',
        ],
      ];
      $variables['#attached']['html_head'][] = [
        $grunticon_fallback,
        'grunticon_fallback',
      ];

      // Icon load is a library, we use drupalSettings so it must load after.
      $variables['#attached']['library'][] = 'toolbar_themes/grunticon_load';
    }
  }

  // Tab icons.
  $variables['show_tabs'] = $config
    ->get('tabs');
  if ($variables['show_tabs'] === 1) {
    if (isset($variables['tabs'])) {
      foreach ($variables['tabs'] as $item_key => $item_values) {

        // Icons.
        if ($variables['show_icons'] === 1) {
          $variables['tabs'][$item_key]['icon_attributes'] = new Attribute();
          $item_classes = $item_values['link']['#attributes']['class'];
          $variables['tabs'][$item_key]['icon_attributes']
            ->addClass($item_classes)
            ->removeClass('toolbar-item', 'trigger');
        }
      }
    }
  }
}