function _nodehierarchy_node_parent_form_items in Node Hierarchy 6.2
Same name and namespace in other branches
- 6.3 nodehierarchy.module \_nodehierarchy_node_parent_form_items()
- 7.4 nodehierarchy.admin.inc \_nodehierarchy_node_parent_form_items()
- 7.2 nodehierarchy.module \_nodehierarchy_node_parent_form_items()
Get the parent and menu setting for items for a given parent menu_link.
1 call to _nodehierarchy_node_parent_form_items()
- nodehierarchy_nodehierarchy_node_form in ./
nodehierarchy.module - Get the node edit form for nodehierarchy.
File
- ./
nodehierarchy.module, line 544 - A module to make nodes hierarchical.
Code
function _nodehierarchy_node_parent_form_items($node, $key, $menu_link) {
// Wrap the item in a div for js purposes
$item = array(
'#type' => 'fieldset',
'#title' => t('Parent'),
'#tree' => TRUE,
'#prefix' => '<div class="nodehierarchy-menu-link">',
'#suffix' => '</div>',
);
// Add the uneditable values so they're saved.
foreach ($menu_link as $i => $value) {
$item[$i] = array(
'#type' => 'value',
'#value' => $value,
);
}
// If a node can be a child of another add a selector to pick the parent. Otherwise set the parent to 0.
if (nodehierarchy_node_can_be_child($node)) {
$item['pnid'] = _nodehierarchy_get_parent_selector($node->type, empty($menu_link['pnid']) ? null : $menu_link['pnid'], empty($node->nid) ? null : $node->nid);
$item['pnid']['#weight'] = -1;
}
else {
$item['pnid'] = array(
'#type' => 'value',
'#value' => 0,
);
}
$item['mlid'] = array(
'#type' => 'value',
'#value' => $menu_link['mlid'],
);
$create_menu = variable_get('nh_createmenu_' . $node->type, 'optional_no');
// Prevent menus from being created for non-primary parents. That prevernts weirdness
// caused by Drupal 6 core's inconsisnency of defining the active menu trail when there
// menu items pointing to the same node.
// TODO: find a way around the weirdness and reenable this.
if ($key > 0) {
$create_menu = 'never';
}
if ((user_access('administer menus') || user_access('customize nodehierarchy menus')) && $create_menu !== 'never') {
if ($create_menu == 'optional_yes' || $create_menu == 'optional_no') {
$item['enabled'] = array(
'#type' => 'checkbox',
'#title' => 'Show in menu',
'#attributes' => array(
'class' => 'nodehierarchy-menu-enable',
),
'#default_value' => @$menu_link['enabled'],
'#description' => t('All of this node\'s ancestors must have this option selected as well for this item to show in the menu.'),
);
}
$item['menu_settings'] = array(
'#prefix' => '<div class="nodehierarchy-menu-settings">',
'#suffix' => '</div>',
'#tree' => FALSE,
);
$item['menu_settings']['menu_name'] = array(
'#type' => 'select',
'#title' => 'Menu',
'#prefix' => '<div class="nodehierarchy-menu-name">',
'#suffix' => '</div>',
'#options' => menu_get_menus(),
'#default_value' => @$menu_link['menu_name'],
'#description' => t('If you do not pick a parent for this node its menu item will appear at the top level of this menu.'),
'#parents' => array(
'nodehierarchy_menu_links',
$key,
'menu_name',
),
);
$item['menu_settings']['customized'] = array(
'#type' => 'checkbox',
'#attributes' => array(
'class' => 'nodehierarchy-menu-customize',
),
'#title' => 'Customize menu title',
'#default_value' => @$menu_link['customized'],
'#parents' => array(
'nodehierarchy_menu_links',
$key,
'customized',
),
'#description' => t('Specify a name for this node\'s menu item that is something other than the node\'s title. Leave unchecked to use the node\'s title.'),
);
$item['menu_settings']['link_title'] = array(
'#type' => 'textfield',
'#prefix' => '<div class="nodehierarchy-menu-title">',
'#suffix' => '</div>',
'#title' => t('Menu link title'),
'#default_value' => @$menu_link['link_title'],
'#description' => t('The link text corresponding to this item that should appear in the menu.'),
'#parents' => array(
'nodehierarchy_menu_links',
$key,
'link_title',
),
);
$item['menu_settings']['expanded'] = array(
'#type' => 'checkbox',
'#title' => t('Expand Menu Item'),
'#default_value' => @$menu_link['expanded'],
'#description' => t('If selected and this menu item has children, the menu will always appear expanded.'),
'#parents' => array(
'nodehierarchy_menu_links',
$key,
'expanded',
),
);
$item['menu_settings']['description'] = array(
'#type' => 'textarea',
'#title' => t('Menu Item Description'),
'#default_value' => isset($menu_link['options']['attributes']['title']) ? $menu_link['options']['attributes']['title'] : '',
'#rows' => 1,
'#description' => t('The description displayed when hovering over a menu item. Hold your mouse over <a href="#" title="This is where the description will appear.">this link</a> for a demonstration.'),
'#parents' => array(
'nodehierarchy_menu_links',
$key,
'description',
),
);
}
// Add the delete menu item checkbox if this is a pre-existing parent item.
if ($key > 0) {
$item['remove'] = array(
'#type' => 'checkbox',
'#title' => t('Remove this parent'),
'#default_value' => isset($menu_link['remove']) ? $menu_link['remove'] : '',
'#description' => t('Remove this parent from this node. This will not delete the parent node.'),
'#attributes' => array(
'class' => 'nodehierarchy-parent-delete',
),
);
}
return $item;
}