summaryrefslogtreecommitdiff
path: root/modules/menu
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-09-09 23:01:48 +0000
committerDries Buytaert <dries@buytaert.net>2010-09-09 23:01:48 +0000
commiteaee909a00a516d864da65e44f8abe5446914c7e (patch)
treef3c52d3b9041e93a8e7000446016cc73b9413f2d /modules/menu
parenta16c46bf8a99745d7fa31cc6f2c34e0b17e7bed6 (diff)
downloadbrdo-eaee909a00a516d864da65e44f8abe5446914c7e.tar.gz
brdo-eaee909a00a516d864da65e44f8abe5446914c7e.tar.bz2
- Patch #757154 by sun, effulgentsia: base form_id() via hook_forms() not taken into account for #validate, #submit, hook_form_FORMID_alter().
Diffstat (limited to 'modules/menu')
-rw-r--r--modules/menu/menu.module157
1 files changed, 81 insertions, 76 deletions
diff --git a/modules/menu/menu.module b/modules/menu/menu.module
index 57db01229..fc7a655b8 100644
--- a/modules/menu/menu.module
+++ b/modules/menu/menu.module
@@ -587,92 +587,96 @@ function _menu_parent_depth_limit($item) {
}
/**
- * Implements hook_form_alter(). Adds menu item fields to the node form.
+ * Implements hook_form_BASE_FORM_ID_alter().
+ *
+ * Adds menu item fields to the node form.
+ *
+ * @see menu_node_submit()
*/
-function menu_form_alter(&$form, $form_state, $form_id) {
- if (!empty($form['#node_edit_form'])) {
- // Generate a list of possible parents.
- // @todo This must be handled in a #process handler.
- $type = $form['#node']->type;
- $options = menu_parent_options(menu_get_menus(), $type);
- // If no possible parent menu items were found, there is nothing to display.
- if (empty($options)) {
- return;
- }
- $link = $form['#node']->menu;
-
- $form['menu'] = array(
- '#type' => 'fieldset',
- '#title' => t('Menu settings'),
- '#access' => user_access('administer menu'),
- '#collapsible' => TRUE,
- '#collapsed' => !$link['link_title'],
- '#group' => 'additional_settings',
- '#attached' => array(
- 'js' => array(drupal_get_path('module', 'menu') . '/menu.js'),
- ),
- '#tree' => TRUE,
- '#weight' => -2,
- '#attributes' => array('class' => array('menu-link-form')),
- );
- $form['menu']['enabled'] = array(
- '#type' => 'checkbox',
- '#title' => t('Provide a menu link'),
- '#default_value' => (int) (bool) $link['mlid'],
- );
- $form['menu']['link'] = array(
- '#type' => 'container',
- '#parents' => array('menu'),
- '#states' => array(
- 'invisible' => array(
- 'input[name="menu[enabled]"]' => array('checked' => FALSE),
- ),
+function menu_form_node_form_alter(&$form, $form_state) {
+ // Generate a list of possible parents.
+ // @todo This must be handled in a #process handler.
+ $type = $form['#node']->type;
+ $options = menu_parent_options(menu_get_menus(), $type);
+ // If no possible parent menu items were found, there is nothing to display.
+ if (empty($options)) {
+ return;
+ }
+ $link = $form['#node']->menu;
+
+ $form['menu'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Menu settings'),
+ '#access' => user_access('administer menu'),
+ '#collapsible' => TRUE,
+ '#collapsed' => !$link['link_title'],
+ '#group' => 'additional_settings',
+ '#attached' => array(
+ 'js' => array(drupal_get_path('module', 'menu') . '/menu.js'),
+ ),
+ '#tree' => TRUE,
+ '#weight' => -2,
+ '#attributes' => array('class' => array('menu-link-form')),
+ );
+ $form['menu']['enabled'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Provide a menu link'),
+ '#default_value' => (int) (bool) $link['mlid'],
+ );
+ $form['menu']['link'] = array(
+ '#type' => 'container',
+ '#parents' => array('menu'),
+ '#states' => array(
+ 'invisible' => array(
+ 'input[name="menu[enabled]"]' => array('checked' => FALSE),
),
- );
+ ),
+ );
- // Populate the element with the link data.
- foreach (array('mlid', 'module', 'hidden', 'has_children', 'customized', 'options', 'expanded', 'hidden', 'parent_depth_limit') as $key) {
- $form['menu']['link'][$key] = array('#type' => 'value', '#value' => $link[$key]);
- }
+ // Populate the element with the link data.
+ foreach (array('mlid', 'module', 'hidden', 'has_children', 'customized', 'options', 'expanded', 'hidden', 'parent_depth_limit') as $key) {
+ $form['menu']['link'][$key] = array('#type' => 'value', '#value' => $link[$key]);
+ }
- $form['menu']['link']['link_title'] = array(
- '#type' => 'textfield',
- '#title' => t('Menu link title'),
- '#default_value' => $link['link_title'],
- );
+ $form['menu']['link']['link_title'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Menu link title'),
+ '#default_value' => $link['link_title'],
+ );
- $form['menu']['link']['description'] = array(
- '#type' => 'textarea',
- '#title' => t('Description'),
- '#default_value' => isset($link['options']['attributes']['title']) ? $link['options']['attributes']['title'] : '',
- '#rows' => 1,
- '#description' => t('Shown when hovering over the menu link.'),
- );
+ $form['menu']['link']['description'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Description'),
+ '#default_value' => isset($link['options']['attributes']['title']) ? $link['options']['attributes']['title'] : '',
+ '#rows' => 1,
+ '#description' => t('Shown when hovering over the menu link.'),
+ );
- $default = ($link['mlid'] ? $link['menu_name'] . ':' . $link['plid'] : variable_get('menu_parent_' . $type, 'main-menu:0'));
- // @todo This will fail with the new selective menus per content type.
- if (!isset($options[$default])) {
- $default = 'navigation:0';
- }
- $form['menu']['link']['parent'] = array(
- '#type' => 'select',
- '#title' => t('Parent item'),
- '#default_value' => $default,
- '#options' => $options,
- '#attributes' => array('class' => array('menu-parent-select')),
- );
- $form['menu']['link']['weight'] = array(
- '#type' => 'weight',
- '#title' => t('Weight'),
- '#delta' => 50,
- '#default_value' => $link['weight'],
- '#description' => t('Menu links with smaller weights are displayed before links with larger weights.'),
- );
+ $default = ($link['mlid'] ? $link['menu_name'] . ':' . $link['plid'] : variable_get('menu_parent_' . $type, 'main-menu:0'));
+ // @todo This will fail with the new selective menus per content type.
+ if (!isset($options[$default])) {
+ $default = 'navigation:0';
}
+ $form['menu']['link']['parent'] = array(
+ '#type' => 'select',
+ '#title' => t('Parent item'),
+ '#default_value' => $default,
+ '#options' => $options,
+ '#attributes' => array('class' => array('menu-parent-select')),
+ );
+ $form['menu']['link']['weight'] = array(
+ '#type' => 'weight',
+ '#title' => t('Weight'),
+ '#delta' => 50,
+ '#default_value' => $link['weight'],
+ '#description' => t('Menu links with smaller weights are displayed before links with larger weights.'),
+ );
}
/**
* Implements hook_node_submit().
+ *
+ * @see menu_form_node_form_alter()
*/
function menu_node_submit($node, $form, $form_state) {
// Decompose the selected menu parent option into 'menu_name' and 'plid', if
@@ -683,7 +687,8 @@ function menu_node_submit($node, $form, $form_state) {
}
/**
- * Implements hook_form_FORM_ID_alter() for the node type form.
+ * Implements hook_form_FORM_ID_alter().
+ *
* Adds menu options to the node type form.
*/
function menu_form_node_type_form_alter(&$form, $form_state) {