When trying to use a menu views menu in the foundation theme, all that happends is it renders out <a href="/%3Cview%3E" title=""></a>

It's seems there is presently no way for foundation to actually render out the view instead of rendering a simple link.

We're pretty urgently seeking this feature, but i'm not deeply into the codebase of ehiter menu_views or foundation, so i don't know how to implement it.

I'm thinking it should be added into _zurb_foundation_render_link, because where is already a case for special_menu_items?

Comments

ropic’s picture

Same problem, any fix ?

zonesny’s picture

I'm scratching at the surface of this compatibility issue as well. In a quest for mega menus that work with Foundation, I've tested a number of modules. In addition to Menu Views module, I've installed the Ultimenu module, which will let you embed a "view block" inside a menu (the module is a bit clunky, but it works). However, I'm using the "tab bar" in my Foundation subtheme, which presents multi-level submenus vertically in the off-canvas section. At the moment, the view block is not being displayed in the off-canvas section, which makes sense, but leads me to ask those of you who have used this menu views before, what should actually be shown in the off-canvas submenu?

zonesny’s picture

I found a solution in this thread about Bootstrap module (credit to rroblik's original comment). The function theme_zurb_foundation_menu_link() (i.e. theme_menu_link) overrides Menu View's menu_views_menu_link(). Here is the code that goes in zurb_foundation's template.php:

//replace existing function body
function theme_zurb_foundation_menu_link(&$variables) {

	$element = $variables['link'];

	if (empty($element) && !is_array($element)) {
		return '';
	}

	if (module_exists('menu_views') && $element['#href'] == '<view>') {
		return _zurb_foundation_menu_views_menu_link($variables);
	}


	return l($element['#title'], $element['#href'], $element['#localized_options']);
}

//this function just replicates menu_views_menu_link() from menu_views module
function _zurb_foundation_menu_views_menu_link(&$variables) {
	// Only intercept if this menu link is a view.
	$view = _menu_views_replace_menu_item($variables['link']);
	if ($view !== FALSE) {
		if (!empty($view)) {
			$sub_menu = '';

			// Optionnal : altering classes or other attributes
			$classes = array();
			$item = _menu_views_get_item($variables['link']); // Function from menu_views module
			foreach (explode(' ', $item['view']['settings']['wrapper_classes']) as $class) {
				if (!in_array($class, $classes)) {
					$classes[] = $class;
				}
			}
			$variables['link']['#attributes']['class'] = $classes;
			// EOF optionnal styling

			if ($variables['link']['#below']) {
				$sub_menu = render($variables['link']['#below']);
			}


			$attr = $variables['link']['#attributes'];
			if (!empty($attr) && is_array($attr)){
				return '<div' . drupal_attributes($variables['link']['#attributes']) . '>' . $view . $sub_menu . '</div>';
			}
			else {
				return '<div' . $variables['link']['#attributes'] . '>' . $view . $sub_menu . '</div>';
			}
		}
		return '';
	}

	return theme('menu_views_menu_link_default', $variables);
}

While these changes will get menu_views working, it's not a great solution. I hate the idea of replicating code (i.e. code smell). Feel free to alter/refactor.

hongpong’s picture

Status: Active » Closed (won't fix)

Thank you zonesny for that workaround. I think we are not in a position to alter the function theme_zurb_foundation_menu_link to make it work with menu_views and I agree this would be a bad code smell because it is duplicative.

see also https://www.drupal.org/project/menu_block and http://palantir.net/blog/use-menus-drupal-7-you-need-menu-block-module for additional options. If there is a patch to call the function on the menu_view this ticket can be reopened, but it is unlikely that the function will otherwise get changed in 7.x-5.x.