You are here

function _nodehierarchy_create_menu in Node Hierarchy 5

Same name and namespace in other branches
  1. 6 nodehierarchy.module \_nodehierarchy_create_menu()

Create a menu item if the user selects one.

1 call to _nodehierarchy_create_menu()
nodehierarchy_nodehierarchyapi in ./nodehierarchy.module
Implementation of hook_nodehierarchyapi(). Responds to own api calls.

File

./nodehierarchy.module, line 939
A module to make nodes hierarchical.

Code

function _nodehierarchy_create_menu(&$node) {

  // If the menu is to be (re)created set the values to that derived by the hierarchy.
  if (function_exists('menu_edit_item_save') && variable_get('nodehierarchy_menus', TRUE) && (user_access('administer menu') || variable_get('nodehierarchy_menu_noadmin', FALSE)) && $node->nodehierarchy_create_menu) {
    if ($parent_menu = _nodehierarchy_get_menu($node->parent)) {
      $node->menu['pid'] = $parent_menu;
    }
    else {
      $node->menu['pid'] = variable_get('nodehierarchy_menus_default', 1);
    }
    $node->menu['path'] = 'node/' . $node->nid;
    $node->menu['title'] = $node->title;
    $node->menu['weight'] = $node->order_by;
    $node->menu['type'] = MENU_CUSTOM_ITEM | MENU_MODIFIED_BY_ADMIN | MENU_VISIBLE_IN_TREE;
    menu_edit_item_save($node->menu);
    menu_rebuild();

    // Prevent the menu.module saving the menu itself in case
    // the module is called after this one.
    $node->menu = array();

    // Prevent the this module from attempting to create a menu twice.
    $node->nodehierarchy_create_menu = FALSE;
  }
}