You are here

function _nodehierarchy_get_parent_selector in Node Hierarchy 7.2

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.4 nodehierarchy.admin.inc \_nodehierarchy_get_parent_selector()

Get the parent selector pulldown.

3 calls to _nodehierarchy_get_parent_selector()
nodehierarchy_form_menu_edit_item_alter in ./nodehierarchy.module
Implements hook_form_menu_edit_item_alter().
_nodehierarchy_get_node_type_settings_form in ./nodehierarchy.module
Get the nodehierarchy setting form for a particular node type.
_nodehierarchy_node_parent_form_items in ./nodehierarchy.module
Get the parent and menu setting for items for a given parent menu_link.

File

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

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 = _nodehierarchy_get_parent_selector_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.
  $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',
      'nodehierarchy_parent_selector_to_nid',
    ),
  );
  return $out;
}