function menu_views_node_prepare in Menu Views 8.3
Same name and namespace in other branches
- 7.2 menu_views.module \menu_views_node_prepare()
Implements hook_node_prepare().
File
- ./
menu_views.module, line 442 - Module to allow Views to be attached as menu items.
Code
function menu_views_node_prepare($node) {
// Manually call menu's hook_node_prepare() if $node->menu doesn't exist.
// @see: drupal.org/node/1878968
if (!isset($node->menu) || empty($node->menu)) {
menu_node_prepare($node);
}
if (isset($node->nid) && !$node->menu['mlid']) {
// Prepare the node for the edit form so that $node->menu always exists.
$menu_name = strtok(variable_get('menu_parent_' . $node->type, 'main-menu:0'), ':');
$item = array();
$mlids = array();
// Give priority to the default menu.
$type_menus = variable_get('menu_options_' . $node->type, array(
'main-menu' => 'main-menu',
));
if (in_array($menu_name, $type_menus)) {
$mlids = _menu_views_items_from_original_path('node/' . $node->nid, $menu_name);
}
// Check all allowed menus if a link does not exist in the default menu.
if (empty($mlid) && !empty($type_menus)) {
$mlids = _menu_views_items_from_original_path('node/' . $node->nid, array_values($type_menus));
}
// Load the menu link if one was found.
$item = empty($mlids) ? array() : menu_link_load(reset($mlids));
// Set default values.
$default = array(
'link_title' => '',
'mlid' => 0,
'plid' => 0,
'menu_name' => $menu_name,
'weight' => 0,
'options' => array(),
'module' => 'menu',
'expanded' => 0,
'hidden' => 0,
'has_children' => 0,
'customized' => 0,
);
// Set the menu item.
$node->menu = _menu_views_array_merge_recursive($default, $item);
// Find the depth limit for the parent select.
if (!isset($node->menu['parent_depth_limit'])) {
$node->menu['parent_depth_limit'] = _menu_parent_depth_limit($node->menu);
}
}
}