You are here

function menu_views_menu_link in Menu Views 7.2

Same name and namespace in other branches
  1. 8.3 menu_views.module \menu_views_menu_link()

Implements theme_menu_link(). Overrides default theming function to intercept views.

1 string reference to 'menu_views_menu_link'
menu_views_theme_registry_alter in ./menu_views.module
Implements hook_theme_registry_alter(). Intercepts theme_menu_link().

File

./menu_views.module, line 68
Module to allow Views to be attached as menu items.

Code

function menu_views_menu_link(array $variables) {

  // Only intercept if this menu link is a view.
  $view = _menu_views_replace_menu_item($variables['element']);
  if ($view !== FALSE) {
    if (!empty($view)) {
      $sub_menu = '';
      $classes = isset($variables['element']['#attributes']['class']) ? $variables['element']['#attributes']['class'] : array();
      $item = _menu_views_get_item($variables['element']);
      foreach (explode(' ', $item['view']['settings']['wrapper_classes']) as $class) {
        if (!in_array($class, $classes)) {
          $classes[] = $class;
        }
      }
      $variables['element']['#attributes']['class'] = $classes;
      if ($variables['element']['#below']) {
        $sub_menu = drupal_render($variables['element']['#below']);
      }
      return '<li' . drupal_attributes($variables['element']['#attributes']) . '>' . $view . $sub_menu . "</li>\n";
    }
    return '';
  }

  // Otherwise, use the default theming function.
  return theme('menu_views_menu_link_default', $variables);
}