You are here

function menu_views_node_presave in Menu Views 7.2

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

Implements hook_node_presave().

File

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

Code

function menu_views_node_presave($node) {
  if (isset($node->menu)) {
    $link =& $node->menu;
    $item = _menu_views_get_item($link);

    // Ensure the enabled property is set.
    if (!isset($link['enabled'])) {
      $link['enabled'] = !(bool) $link['hidden'];
    }

    // If this is a menu view item, override properties on the link so this module handles the save.
    if ($link['enabled'] && $item['type'] == 'view') {

      // Save the mlid in the menu_views array so the menu module doesn't delete the link when it detects the mlid.
      if (!empty($link['mlid'])) {
        $link['options']['menu_views']['mlid'] = $link['mlid'];
        $link['mlid'] = 0;
      }

      // Ensure there is no title so the menu module doesn't try to save this menu item.
      $link['link_title'] = '';
    }
  }
}