You are here

function nodehierarchy_nodehierarchy_default_parents in Node Hierarchy 6.2

Same name and namespace in other branches
  1. 6.3 nodehierarchy.module \nodehierarchy_nodehierarchy_default_parents()
  2. 7.4 nodehierarchy.module \nodehierarchy_nodehierarchy_default_parents()
  3. 7.2 nodehierarchy.module \nodehierarchy_nodehierarchy_default_parents()

Set the default parents for a node.

File

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

Code

function nodehierarchy_nodehierarchy_default_parents(&$node) {
  $plid = NULL;
  if (nodehierarchy_node_can_be_child($node) || nodehierarchy_node_can_be_parent($node)) {
    if (!isset($node->nodehierarchy_menu_links) || empty($node->nodehierarchy_menu_links)) {

      // Should this menu item be enabled or not.
      $create_menu = variable_get('nh_createmenu_' . $node->type, 'optional_no');
      $enabled = $create_menu == 'optional_yes' || $create_menu == 'always';

      // Create a default menu_link object.
      $menu_link = _nodehierarchy_default_menu_link($node->nid, 0, $enabled);

      // Set the type default if there is one.
      if (empty($node->nid)) {
        $default = variable_get('nh_defaultparent_' . $node->type, 0);

        // Get the parent node id from passed in from the get params.
        $pnid = !empty($_GET['parent']) ? (int) $_GET['parent'] : $default;

        // Get the parent from the get string. User must have update perms for parent unless it is the default.
        if ($pnid && ($parent_node = node_load($pnid))) {
          if (nodehierarchy_node_can_be_parent($parent_node) && (user_access('create child of any parent') || node_access("update", $parent_node) || $parent_node->nid == $default)) {
            $menu_link['pnid'] = $pnid;
          }
        }
      }
      $node->nodehierarchy_menu_links[] = $menu_link;
    }
  }
}