You are here

function responsive_menu_off_canvas_add_class in Responsive and off-canvas menu 4.3.x

Recursively adds the uuid of each menu item as a class.

Parameters

array $item: The render array of a menu item.

1 call to responsive_menu_off_canvas_add_class()
responsive_menu_responsive_menu_off_canvas_tree_alter in ./responsive_menu.module
Implements hook_responsive_menu_off_canvas_tree_alter().

File

./responsive_menu.module, line 243
Contains procedural code.

Code

function responsive_menu_off_canvas_add_class(array &$item) {
  if (!empty($item['original_link'])) {
    $link = $item['original_link'];
    $id = $link
      ->getPluginId();

    // User created menu link ids take the form 'menu_link_content:{uuid}'.
    if (strpos($id, ':')) {
      $parts = explode(':', $id);
    }
    else {
      $parts = explode('.', $id);
    }
    $uuid = Html::cleanCssIdentifier($parts[1]);
    $item['attributes']
      ->addClass('menu-item--' . $uuid);
  }
  if (!empty($item['below'])) {
    foreach ($item['below'] as &$below) {
      responsive_menu_off_canvas_add_class($below);
    }
  }
}