<?php

/**
 * @file
 * preprocess-menu.php
 *
 * Define all view preprocess HOOKs.
 */

/**
 * Implements hook_preprocess_menu().
 */
function s360_base_theme_preprocess_menu(&$variables) {
  $menu_name = $variables['menu_name'];

  if (!in_array($menu_name, ['admin', 'devel'])) {
    // Clear any Drupal classes.
    $variables['attributes']['class'] = [];
  }
}

/**
 * Implements hook_preprocess_menu_local_task().
 */
function s360_base_theme_preprocess_menu_local_task(&$variables) {
  $variables['attributes']['class'] = [];
  $variables['attributes']['class'][] = 'menu__item';
}

/**
 * Implements hook_preprocess_menu() for social.
 */
function s360_base_theme_preprocess_menu__social(&$variables) {
  $site_name = \Drupal::config('system.site')->get('name');

  foreach ($variables['items'] as &$item) {
    $item_title = &$item['title'];

    $item['url']->setOptions([
      'attributes' => [
        'aria-label' => "Go to $site_name's $item_title page",
        'title' => $item_title,
      ],
    ]);
  }
}
