function _menu_views_replace_menu_item in Menu Views 7.2
Same name and namespace in other branches
- 8.3 menu_views.module \_menu_views_replace_menu_item()
3 calls to _menu_views_replace_menu_item()
- menu_views_menu_link in ./
menu_views.module - Implements theme_menu_link(). Overrides default theming function to intercept views.
- menu_views_responsive_dropdown_menus_item_link in ./
menu_views.module - Implements theme_responsive_dropdown_menus_item_link(). Overrides default theming function to intercept views.
- menu_views_superfish_menu_item_link in ./
menu_views.module - Implements theme_superfish_menu_item_link(). Overrides default theming function to intercept views.
File
- ./
menu_views.module, line 169 - Module to allow Views to be attached as menu items.
Code
function _menu_views_replace_menu_item($element) {
$build = array();
$item = _menu_views_get_item($element);
_menu_views_tokenize($item);
if ($item['type'] == 'view' && $item['view']['name'] && $item['view']['display']) {
$element['#attributes']['class'][] = 'menu-views';
if ($view = views_get_view($item['view']['name'])) {
if ($view
->access($item['view']['display']) && $view
->set_display($item['view']['display'])) {
$arguments = explode('/', $item['view']['arguments']);
// Need to replace empty arguments with NULL values for views.
foreach ($arguments as $key => $value) {
if (empty($value)) {
$arguments[$key] = NULL;
}
}
$view
->set_arguments($arguments);
$build['view'] = array(
'#markup' => $view
->preview(),
'#weight' => 10,
);
// Provide title options for the view.
if ((bool) $item['view']['settings']['title']) {
$title = filter_xss_admin($item['view']['settings']['title_override']);
if (empty($title)) {
$title = filter_xss_admin($view
->get_title());
}
if (!empty($title)) {
$tag = $item['view']['settings']['title_wrapper'];
if ($tag === '0') {
$tag = FALSE;
}
elseif ($tag === '') {
$tag = 'h3';
}
if ($tag) {
$title_attributes = array();
if (!empty($item['view']['settings']['title_classes'])) {
$title_attributes['class'] = array_filter(explode(' ', $item['view']['settings']['title_classes']));
foreach ($title_attributes['class'] as $key => $class) {
$title_attributes['class'][$key] = drupal_html_class($class);
}
}
$build['title'] = array(
'#theme' => 'html_tag__menu_views__title',
'#tag' => $tag,
'#attributes' => $title_attributes,
'#value' => filter_xss_admin($title),
);
}
else {
$build['title'] = array(
'#markup' => $title,
);
}
}
}
// Add contextual links if allowed and if views_ui module is enabled.
if (module_exists('contextual_links') && user_access('access contextual links') && module_exists('views_ui')) {
views_add_contextual_links($build, 'special_block_-exp', $view, $item['view']['display']);
if (!empty($build['#contextual_links'])) {
$build['#prefix'] = '<div class="contextual-links-region">';
$build['#suffix'] = '</div>';
$build['contextual_links'] = array(
'#type' => 'contextual_links',
'#contextual_links' => $build['#contextual_links'],
'#element' => $build,
'#weight' => -1,
);
}
}
$view
->destroy();
}
}
return drupal_render($build);
}
return FALSE;
}