function menu_position_rule_form in Menu Position 6
Same name and namespace in other branches
- 7.2 menu_position.admin.inc \menu_position_rule_form()
- 7 menu_position.admin.inc \menu_position_rule_form()
Returns form to add or edit a menu position rule.
2 calls to menu_position_rule_form()
- menu_position_add_rule_form in ./
menu_position.admin.inc - Menu callback; Adds rules.
- menu_position_edit_rule_form in ./
menu_position.admin.inc - Menu callback; Edits rules.
File
- ./
menu_position.admin.inc, line 344 - Provides infrequently used functions and hooks for menu_position.
Code
function menu_position_rule_form(&$form_state) {
// Set the default values.
$rid = !empty($form_state['#menu-position-rule']['rid']) ? $form_state['#menu-position-rule']['rid'] : '';
$admin_title = !empty($form_state['#menu-position-rule']['admin_title']) ? $form_state['#menu-position-rule']['admin_title'] : '';
$menu_name = !empty($form_state['#menu-position-rule']['menu_name']) ? $form_state['#menu-position-rule']['menu_name'] : '';
$plid = !empty($form_state['#menu-position-rule']['plid']) ? $form_state['#menu-position-rule']['plid'] : NULL;
$mlid = !empty($form_state['#menu-position-rule']['mlid']) ? $form_state['#menu-position-rule']['mlid'] : NULL;
$form['rid'] = array(
'#type' => 'hidden',
'#value' => $rid,
);
$form['admin_title'] = array(
'#type' => 'textfield',
'#default_value' => $admin_title,
'#title' => t('Administrative title'),
'#description' => t('This title will be used administratively to identify this rule.'),
'#required' => TRUE,
);
// Place holder for all condition plug-ins.
// Visibility settings.
$form['conditions_title'] = array(
'#type' => 'item',
'#title' => t('Conditions'),
);
$form['conditions'] = array();
// Parent menu item.
if ($mlid) {
$options = menu_parent_options(menu_get_menus(), menu_link_load($mlid));
$default = $menu_name . ':' . $plid;
}
else {
$options = menu_parent_options(menu_get_menus(), array(
'mlid' => 0,
));
$default = 'main-menu:0';
}
$form['plid'] = array(
'#type' => 'select',
'#title' => t('Menu item'),
'#required' => TRUE,
'#options' => $options,
'#default_value' => $default,
);
if ($rid) {
$form['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
);
}
else {
$form['cancel'] = array(
'#type' => 'submit',
'#value' => t('Cancel'),
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
// Add conditions.
foreach (menu_position_get_plugins() as $plugin) {
// Load the required include file.
if (!empty($plugin['file'])) {
$file = pathinfo($plugin['file']);
// Allow plugins to be in a sub-directory.
if ($file['dirname']) {
$file['filename'] = $file['dirname'] . '/' . $file['filename'];
}
module_load_include($file['extension'], $plugin['module'], $file['filename']);
}
// Call form callback to add additional form elements.
$function = $plugin['form_callback'];
if (function_exists($function)) {
$function($form, $form_state);
}
}
// Form validation and submission.
$form['#validate'][] = 'menu_position_rule_form_validate';
$form['#submit'][] = 'menu_position_rule_form_submit';
return $form;
}