You are here

function _nodehierarchy_parent_options in Node Hierarchy 7.4

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

Return a list of menu items that are valid possible parents for the given node.

1 call to _nodehierarchy_parent_options()
_nodehierarchy_get_parent_selector in ./nodehierarchy.admin.inc
Get the parent selector pulldown.

File

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

Code

function _nodehierarchy_parent_options($child_type, $exclude = NULL) {
  $options =& drupal_static(__FUNCTION__);

  // If these options have already been generated, then return that saved version.
  if (isset($options[$child_type][$exclude])) {
    return $options[$child_type][$exclude];
  }

  // Get all the possible parents.
  // @TODO: implement this if needed. Early testing shows a negligible difference.
  // $parent_tree = array();
  // $cache = cache_get('nodehierarchy_parent_options');
  // if (isset($cache->data)) {
  //   $parent_tree = $cache->data;
  // }
  // else
  $types = nodehierarchy_get_allowed_parent_types();
  $parent_types = nodehierarchy_get_allowed_parent_types($child_type);

  // Build the whole tree.
  $parent_tree = _nodehierarchy_nodes_by_type($types);
  $parent_tree = _nodehierarchy_build_tree($parent_tree);

  // Remove or disable items that can't be parents.
  $parent_tree = _nodehierarchy_tree_disable_types($parent_tree, $parent_types);

  // cache_set('nodehierarchy_parent_options', $parent_tree);

  // Remove items which the user does not have permission to.
  $parent_tree = _nodehierarchy_tree_disable_noaccess($parent_tree);

  // Remove the excluded item(s). This prevents a child being assigned as it's own parent.
  $out = _nodehierarchy_tree_remove_nid($parent_tree, $exclude);

  // Convert the tree to a flattened list (with depth)
  $out = _nodehierarchy_flatten_tree($out);

  // Static caching to prevent these options being built more than once.
  $options[$child_type][$exclude] = $out;
  return $out;
}