You are here

function toolbar_themes_preprocess_toolbar_themes__menu in Toolbar Themes 8

Preprocess variables for menu templates.

Parameters

$variables:

1 string reference to 'toolbar_themes_preprocess_toolbar_themes__menu'
toolbar_themes_theme_registry_alter in ./toolbar_themes.module
Implements hook_theme_registry_alter(). ...well this seems repetitive. TODO, abstract something or?

File

./toolbar_themes.module, line 363

Code

function toolbar_themes_preprocess_toolbar_themes__menu(&$variables) {
  $show_icons = \Drupal::config('toolbar_themes.settings')
    ->get('icons');
  foreach ($variables['items'] as $item_key => $item_values) {
    $variables['items'][$item_key]['show_icon'] = 0;
    $attr = $item_values['url']
      ->getOption('attributes') ?: [];
    $item_classes = isset($attr['class']) ? $attr['class'] : '';
    $item_values['url']
      ->setOption('attributes', [
      'class' => [
        'toolbar-menu__link',
      ],
    ]);
    if ($show_icons === 1) {
      $variables['items'][$item_key]['icon_attributes'] = new Attribute();
      $variables['items'][$item_key]['icon_attributes']
        ->addClass($item_classes);
      $variables['items'][$item_key]['show_icon'] = 1;
    }
  }
}