You are here

function menu_views_node_save in Menu Views 7.2

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

Helper for hook_node_insert() and hook_node_update().

2 calls to menu_views_node_save()
menu_views_node_insert in ./menu_views.module
Implements hook_node_insert().
menu_views_node_update in ./menu_views.module
Implements hook_node_update().

File

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

Code

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

    // Check to see if Menu Views should handle the menu item save.
    if (!empty($link['enabled']) && $item['type'] == 'view') {

      // If this an existing menu item, check to see if the mlid was saved in the menu view options array.
      if (!empty($item['mlid']) && empty($link['mlid'])) {
        $link['mlid'] = $item['mlid'];
      }
      elseif (empty($link['mlid'])) {
        if (!menu_link_save($link)) {
          drupal_set_message(t('There was an error saving the menu link.'), 'error');
          return;
        }
      }

      // Ensure mlid is properly set.
      $item['mlid'] = $link['mlid'];

      // Ensure link_path is properly set.
      $link['link_path'] = '<view>';

      // Ensure original_path is properly set.
      $item['original_path'] = 'node/' . $node->nid;

      // Replace the menu view options in the link and save it.
      $link['options']['menu_views'] = $item;
      if (!menu_link_save($link)) {
        drupal_set_message(t('There was an error saving the menu link.'), 'error');
      }
    }
  }
}