1 menu.admin.inc | menu_edit_menu($form, &$form_state, $type, $menu = array()) |
Menu callback; Build the form that handles the adding/editing of a custom menu.
File
- core/
modules/ menu/ menu.admin.inc, line 526 - Admin page callbacks for the Menu module.
Code
function menu_edit_menu($form, &$form_state, $type, $menu = array()) {
$system_menus = menu_list_system_menus();
if (empty($menu['menu_name'])) {
backdrop_set_title(t('Add menu'));
}
$menu += array(
'menu_name' => '',
'old_name' => !empty($menu['menu_name']) ? $menu['menu_name'] : '',
'title' => '',
'description' => '',
);
// Allow menu_edit_menu_submit() and other form submit handlers to determine
// whether the menu already exists.
$form['#insert'] = empty($menu['old_name']);
$form['old_name'] = array(
'#type' => 'value',
'#value' => $menu['old_name'],
);
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#default_value' => $menu['title'],
'#required' => TRUE,
);
$form['menu_name'] = array(
'#type' => 'machine_name',
'#title' => t('Menu name'),
'#default_value' => $menu['menu_name'],
'#maxlength' => MENU_MAX_MENU_NAME_LENGTH_UI,
'#description' => t('A unique name to construct the URL for the menu. It must only contain lowercase letters, numbers and hyphens.'),
'#field_prefix' => empty($menu['old_name']) ? 'menu-' : '',
'#machine_name' => array(
'exists' => 'menu_edit_menu_name_exists',
'source' => array('title'),
'replace_pattern' => '[^a-z0-9-]+',
'replace' => '-',
),
// A menu's machine name cannot be changed.
'#disabled' => !empty($menu['old_name']) || isset($system_menus[$menu['menu_name']]),
);
$form['description'] = array(
'#type' => 'textarea',
'#title' => t('Description'),
'#default_value' => $menu['description'],
);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
// Only custom menus may be deleted.
$form['actions']['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
'#access' => $type == 'configure' && !isset($system_menus[$menu['menu_name']]),
'#submit' => array('menu_custom_delete_submit'),
);
return $form;
}