You are here

function template_preprocess_superfish in Superfish 8

Prepares variables for the Superfish menu template.

Default template: superfish.html.twig.

Parameters

array $variables: An associative array containing:

  • element: An associative array containing the properties of the element. Properties used: #menu_name, #html_id, #settings, #tree

    • menu_name: Unique menu identifier.
    • html_id: Unique HTML ID.
    • settings: Menu block settings.
    • tree: The menu tree.

See also

superfish.html.twig

File

./superfish.theme.inc, line 31
Preprocessors and theme functions of the Superfish module.

Code

function template_preprocess_superfish(array &$variables) {
  $element = $variables['element'];
  $menu_items_rendered = [
    '#theme' => 'superfish_menu_items',
    '#menu_name' => $element['#menu_name'],
    '#tree' => $element['#tree'],
    '#settings' => $element['#settings'],
    '#cloned_parent' => FALSE,
  ];
  $direction = \Drupal::languageManager()
    ->getCurrentLanguage()
    ->getDirection();
  $menu_classes = [
    'menu',
    'sf-menu',
  ];
  $menu_classes[] = 'sf-' . $element['#menu_name'];
  $menu_classes[] = 'sf-' . $element['#settings']['menu_type'];
  $menu_classes[] = 'sf-style-' . $element['#settings']['style'];
  $menu_classes[] = $direction === LanguageInterface::DIRECTION_RTL ? 'rtl' : '';
  if (strpos($element['#settings']['ulclass'], ' ') !== FALSE) {
    $l = explode(' ', $element['#settings']['ulclass']);
    foreach ($l as $c) {
      $menu_classes[] = Html::cleanCssIdentifier($c);
    }
  }
  else {
    $menu_classes[] = Html::cleanCssIdentifier($element['#settings']['ulclass']);
  }
  $menu_classes = implode(' ', superfish_array_filter($menu_classes));
  $variables['id'] = $element['#html_id'];
  $variables['menu_classes'] = $menu_classes;
  $variables['menu_items'] = $menu_items_rendered;
}