You are here

function _nodehierarchy_get_parent_selector in Node Hierarchy 7.4

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

Get the parent selector pulldown.

2 calls to _nodehierarchy_get_parent_selector()
_nodehierarchy_get_node_type_settings_form in ./nodehierarchy.admin.inc
Get the nodehierarchy setting form for a particular node type.
_nodehierarchy_node_parent_form_items in ./nodehierarchy.admin.inc
Get the parent and menu setting for items for a given parent menu_link.

File

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

Code

function _nodehierarchy_get_parent_selector($child_type, $parent, $exclude = NULL) {

  // Allow other modules to create the pulldown first.
  // Modules implementing this hook, should return the form element inside an array with a numeric index.
  // This prevents module_invoke_all from merging the outputs to make an invalid form array.
  $out = module_invoke_all('nodehierarchy_get_parent_selector', $child_type, $parent, $exclude);
  if ($out) {

    // Return the last element defined (any others are thrown away);
    return end($out);
  }
  $default_value = $parent;

  // If no other modules defined the pulldown, then define it here.
  $options = array(
    0 => '-- ' . t('NONE') . ' --',
  );
  $items = _nodehierarchy_parent_options($child_type, $exclude);
  foreach ($items as $key => $item) {
    $options[$key] = _nodehierarchy_parent_option_title($item);
  }

  // Make sure the current value is enabled so items can be resaved.
  if ($default_value && isset($items[$default_value])) {
    $items[$default_value]->disabled = 0;
  }
  $out = array(
    '#type' => 'select',
    '#title' => t('Parent Node'),
    '#default_value' => $default_value,
    '#attributes' => array(
      'class' => array(
        'nodehierarchy-parent-selector',
      ),
    ),
    '#options' => $options,
    '#items' => $items,
    '#theme' => 'nodehierarchy_parent_selector',
    '#element_validate' => array(
      'nodehierarchy_parent_selector_validate',
    ),
  );
  return $out;
}