You are here

function _nodehierarchy_nodehierarchy_default_parents in Node Hierarchy 7.4

Set the default parents for a node.

1 call to _nodehierarchy_nodehierarchy_default_parents()
nodehierarchy_nodehierarchy_default_parents in ./nodehierarchy.module
Implements hook_nodehierarchy_default_parents().

File

./nodehierarchy.admin.inc, line 848
Admin functions for Node Hierarchy

Code

function _nodehierarchy_nodehierarchy_default_parents(&$node) {
  if (nodehierarchy_node_can_be_child($node) || nodehierarchy_node_can_be_parent($node)) {
    if (!isset($node->nodehierarchy_parents) || empty($node->nodehierarchy_parents)) {

      // Create a default nodeheirarchy object.
      $nid = empty($node->nid) ? null : $node->nid;
      $parent = _nodehierarchy_default_record($nid, 0);

      // 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)) {
            $parent->pnid = $pnid;
          }
        }
      }
      $node->nodehierarchy_parents[] = $parent;
    }
  }
}