function _nodehierarchy_node_parent_form_items in Node Hierarchy 6.3
Same name and namespace in other branches
- 6.2 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 598 - 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)) {
// Determine if Parent Menu can be changed on node edit
$nh_parent_node_override = (bool) variable_get('nh_parent_node_override_' . $node->type, TRUE);
$pnid = $menu_link['pnid'] ? $menu_link['pnid'] : variable_get('nh_parent_node_' . $node->type, 0);
$item['pnid'] = _nodehierarchy_get_parent_selector($node->type, $pnid, $node->nid);
// If dropdown is disabled, filter the options so they cannot simply re-enable it and save at will.
if (!$nh_parent_node_override) {
$item['pnid']['#options'] = array(
$item['pnid']['#default_value'] => $item['pnid']['#options'][$item['pnid']['#default_value']],
);
}
$item['pnid']['#weight'] = -1;
$item['pnid']['#disabled'] = !$nh_parent_node_override;
}
else {
$item['pnid'] = array(
'#type' => 'value',
'#value' => 0,
);
}
$item['mlid'] = array(
'#type' => 'value',
'#value' => $menu_link['mlid'],
);
$create_menu = variable_get('nh_menu_create_' . $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 (!isset($menu_link['enabled']) || $menu_link['enabled'] === FALSE) {
if ($create_menu == 'optional_yes' || $create_menu == 'always') {
$menu_link['enabled'] = 1;
}
else {
$menu_link['enabled'] = 0;
}
}
// Determine if create menu item can be displayed on node edit
$create_menu_disabled = $expand_menu == 'always' ? TRUE : FALSE;
if ($create_menu == 'optional_yes' || $create_menu == 'optional_no') {
$item['enabled'] = array(
'#type' => 'checkbox',
'#disabled' => $create_menu_disabled,
'#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,
);
// Determine if Parent Menu can be changed on node edit
$nh_menu_change_parent = (bool) variable_get('nh_menu_change_parent_' . $node->type, TRUE);
$menus = menu_get_menus();
// If dropdown is disabled, filter the options so they cannot simply re-enable it and save at will.
if (!$nh_menu_change_parent) {
$menus = array(
$menu_link['menu_name'] => $menus[$menu_link['menu_name']],
);
}
$item['menu_settings']['menu_name'] = array(
'#type' => 'select',
'#disabled' => !$nh_menu_change_parent,
'#title' => 'Menu',
'#prefix' => '<div class="nodehierarchy-menu-name">',
'#suffix' => '</div>',
'#options' => $menus,
'#default_value' => @$menu_link['menu_name'],
'#description' => t('The menu where this node\'s menu item is placed.'),
'#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',
),
);
$expand_menu = variable_get('nh_menu_expand_' . $node->type, 'optional_no');
if (!isset($menu_link['expanded'])) {
if ($expand_menu == 'optional_yes' || $expand_menu == 'always') {
$menu_link['expanded'] = 1;
}
else {
$menu_link['expanded'] = 0;
}
}
// Determine if Expand menu item can be displayed on node edit
$expand_menu_disabled = $expand_menu == 'never' || $expand_menu == 'always' ? TRUE : FALSE;
$item['menu_settings']['expanded'] = array(
'#type' => 'checkbox',
'#disabled' => $expand_menu_disabled,
'#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;
}