From 28fdb3975e2bc53061277f4fdb1147dc8d3ba128 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Mon, 5 Dec 2005 09:11:33 +0000 Subject: - Patch #39778 by chx: obliterate nodeapi op form in favor of the forms API's way of doing things. Tested with help from webchick. --- modules/menu/menu.module | 228 ++++++++++++++++++----------------------------- 1 file changed, 88 insertions(+), 140 deletions(-) (limited to 'modules/menu/menu.module') diff --git a/modules/menu/menu.module b/modules/menu/menu.module index eea4e0522..1eb896873 100644 --- a/modules/menu/menu.module +++ b/modules/menu/menu.module @@ -106,21 +106,17 @@ function menu_configure() { $primary_options[$mid] = $menu['items'][$mid]['title']; } - $form['settings_links'] = array( - '#type' => 'fieldset', - '#title' => t('Primary links settings'), - ); - + $form['settings_links'] = array('#type' => 'fieldset', '#title' => t('Primary links settings')); $form['settings_links']['intro'] = array( - '#type' => 'item', - '#value' => t('Primary links is a navigation system which usually (depending on your theme) appears at the top-right of the browser window. There are usually two rows of links, primary and secondary. You may control which links appear in this area by choosing a menu from which the links will be generated and then placing your links into the menu using the menu administration or the menu settings pane on each post authoring form.', array('%menu' => url('admin/menu'))), + '#type' => 'markup', + '#value' => t('Primary links is a navigation system which usually (depending on your theme) appears at the top-right of the browser window. There are usually two rows of links, primary and secondary. You may control which links appear in this area by choosing a menu from which the links will be generated and then placing your links into the menu using the menu administration or the \'Menu settings\' pane on each edit node form.', array('%menu' => url('admin/menu'))) ); $form['settings_links']['menu_primary_menu'] = array( '#type' => 'select', '#title' => t('Menu containing primary links'), '#default_value' => variable_get('menu_primary_menu', 0), - '#options' => $primary_options, + '#options' => $primary_options ); $secondary_options[0] = t('No secondary links'); @@ -133,32 +129,9 @@ function menu_configure() { '#title' => t('Menu containing secondary links'), '#default_value' => variable_get('menu_secondary_menu', 0), '#options' => $secondary_options, - '#description' => t('If you select the same menu as primary links then secondary links will display the appropriate second level of your navigation hierarchy.'), - ); - - $form['settings_authoring'] = array( - '#type' => 'fieldset', - '#title' => t('Post authoring form settings'), - ); - - $form['settings_authoring']['intro'] = array( - '#type' => 'item', - '#value' => t('On each post authoring form there is a menu settings pane. This setting allows you to limit what is displayed in the parent item drop-down menu of that pane. This can be used to force new menu items to be created in the primary links menu or to hide admin menu items.'), + '#description' => t('If you select the same menu as primary links then secondary links will display the appropriate second level of your navigation hierarchy.') ); - $authoring_options = array(0 => t('Show all menus')); - foreach ($menu['items'][0]['children'] as $mid) { - $authoring_options[$mid] = $menu['items'][$mid]['title']; - } - - $form['settings_authoring']['menu_parent_items'] = array( - '#type' => 'select', - '#title' => t('Restrict parent items to'), - '#default_value' => variable_get('menu_parent_items', 0), - '#options' => $authoring_options, - '#description' => t('Choose the menu from which parent items will be made available. Only this menu item and its children will be shown.'), - ); - return system_settings_form('menu_configure', $form); } @@ -192,12 +165,6 @@ function menu_nodeapi(&$node, $op) { if (user_access('administer menu')) { switch ($op) { - case 'form': - $edit = isset($_POST['edit']) ? $_POST['edit'] : ''; - $edit['nid'] = isset($node->nid) ? $node->nid : ''; - return menu_node_form($edit); - break; - case 'insert': case 'update': if ($node->menu['delete']) { @@ -593,51 +560,29 @@ function menu_overview_tree_rows($pid = 0, $depth = 0) { /** * Return a list of menu items that are valid possible parents for the - * given menu item. The list excludes the given item and its children. - * - * @param $mid - * The menu item id for which to generate a list of parents. - * If $mid == 0 then the complete tree is returned. - * @param $pid - * The menu item id of the menu item at which to start the tree. - * If $pid > 0 then this item will be included in the tree. - * @param $depth - * The current depth in the tree - used when recursing to indent the tree. - * @return - * An array of menu titles keyed on the mid. + * given menu item. */ function menu_parent_options($mid, $pid = 0, $depth = 0) { $menu = menu_get_menu(); $options = array(); - if (!isset($menu['items'][$pid])) { - return $options; - } - - // Exclude $mid and its children from the list unless $mid is 0. - if ($mid && $mid == $pid) { - return $options; - } - - // Add the current $pid to the list. - if ($pid > 0 && ($menu['items'][$pid]['type'] & (MENU_MODIFIABLE_BY_ADMIN | MENU_IS_ROOT))) { - $title = ' '. $menu['items'][$pid]['title']; - for ($i = 0; $i < $depth; $i++) { - $title = '--'. $title; - } - if (!($menu['items'][$pid]['type'] & MENU_VISIBLE_IN_TREE)) { - $title .= ' ('. t('disabled') .')'; - } - $options[$pid] = $title; - $depth ++; - } - - // Add children of $pid to the list recursively. - if ($menu['items'][$pid]['children']) { + if (isset($menu['items'][$pid]) && $menu['items'][$pid]['children']) { usort($menu['items'][$pid]['children'], '_menu_sort'); foreach ($menu['items'][$pid]['children'] as $child) { - $options += menu_parent_options($mid, $child, $depth); + if ($child != $mid) { + if ($child > 0 && ($menu['items'][$child]['type'] & (MENU_MODIFIABLE_BY_ADMIN | MENU_IS_ROOT))) { + $title = ' '. $menu['items'][$child]['title']; + for ($i = 0; $i < $depth; $i++) { + $title = '--'. $title; + } + if (!($menu['items'][$child]['type'] & (MENU_VISIBLE_IN_TREE | MENU_VISIBLE_IF_HAS_CHILDREN))) { + $title .= ' ('. t('disabled') .')'; + } + $options[$child] = $title; + } + $options += menu_parent_options($mid, $child, $depth + 1); + } } } @@ -647,84 +592,87 @@ function menu_parent_options($mid, $pid = 0, $depth = 0) { /** * Add menu item fields to the node form. */ -function menu_node_form($edit = array()) { - $item = array(); - if ($edit['nid'] > 0) { - $item = db_fetch_array(db_query("SELECT * FROM {menu} WHERE path = 'node/%d'", $edit['nid'])); - if (is_array($edit['menu'])) { - $item = !is_array($item) ? $edit['menu'] : (($_POST['op'] == t('Preview')) ? array_merge($item, $edit['menu']) : array_merge($edit['menu'], $item)); +function menu_form_alter($form_id, &$form) { + if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) { + $edit = isset($_POST['edit']) ? $_POST['edit'] : ''; + $edit['nid'] = $form['nid']['#value']; + + $item = array(); + if ($edit['nid'] > 0) { + $item = db_fetch_array(db_query("SELECT * FROM {menu} WHERE path = 'node/%d'", $edit['nid'])); + if (is_array($edit['menu'])) { + $item = !is_array($item) ? $edit['menu'] : (($_POST['op'] == t('Preview')) ? array_merge($item, $edit['menu']) : array_merge($edit['menu'], $item)); + } } - } - $form['menu'] = array( - '#type' => 'fieldset', - '#title' => t('Menu settings'), - '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#tree' => TRUE, - ); - - $form['menu']['title'] = array( - '#type' => 'textfield', - '#title' => t('Title'), - '#default_value' => $item['title'], - '#description' => t('The name to display for this link.'), - ); - - $form['menu']['description'] = array( - '#type' => 'textfield', - '#title' => t('Description'), - '#default_value' => $item['description'], - '#description' => t('The description displayed when hovering over a menu item.'), - ); + $form['menu'] = array( + '#type' => 'fieldset', + '#title' => t('Menu settings'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#tree' => TRUE, + ); - // Generate a list of possible parents. - $options = menu_parent_options($item['mid'], variable_get('menu_parent_items', 0)); + $form['menu']['title'] = array( + '#type' => 'textfield', + '#title' => t('Title'), + '#default_value' => $item['title'], + '#description' => t('The name to display for this link.'), + ); - $form['menu']['pid'] = array( - '#type' => select, - '#title' => t('Parent item'), - '#default_value' => $item['pid'], - '#options' => $options, - ); + $form['menu']['description'] = array( + '#type' => 'textfield', + '#title' => t('Description'), + '#default_value' => $item['description'], + '#description' => t('The description displayed when hovering over a menu item.'), + ); - $form['menu']['path'] = array( - '#type' => 'hidden', - '#value' => $item['path'], - ); + // Generate a list of possible parents. + $options = menu_parent_options($item['mid'], variable_get('menu_parent_items', 0)); - $form['menu']['weight'] = array( - '#type' => 'weight', - '#title' => t('Weight'), - '#default_value' => $item['weight'], - '#delta' => 10, - '#description' => t('Optional. In the menu, the heavier items will sink and the lighter items will be positioned nearer the top.'), - ); + $form['menu']['pid'] = array( + '#type' => select, + '#title' => t('Parent item'), + '#default_value' => $item['pid'], + '#options' => $options, + ); - $form['menu']['mid'] = array( - '#type' => 'hidden', - '#value' => $item['mid'] ? $item['mid'] : 0, - ); + $form['menu']['path'] = array( + '#type' => 'hidden', + '#value' => $item['path'], + ); - $form['menu']['type'] = array( - '#type' => 'hidden', - '#value' => $item['type'] ? $item['type'] : MENU_CUSTOM_ITEM, - ); + $form['menu']['weight'] = array( + '#type' => 'weight', + '#title' => t('Weight'), + '#default_value' => $item['weight'], + '#delta' => 10, + '#description' => t('Optional. In the menu, the heavier items will sink and the lighter items will be positioned nearer the top.'), + ); - if ($item['mid'] > 0) { - $form['menu']['delete'] = array( - '#type' => 'checkbox', - '#title' => t('Check to delete this menu item.'), - '#default_value' => $item['delete'], + $form['menu']['mid'] = array( + '#type' => 'hidden', + '#value' => $item['mid'] ? $item['mid'] : 0, ); - $form['menu']['advanced'] = array( - '#type' => 'item', - '#value' => t('You may also edit the advanced settings for this menu item.', array('%edit' => url("admin/menu/item/edit/{$item['mid']}"))), + $form['menu']['type'] = array( + '#type' => 'hidden', + '#value' => $item['type'] ? $item['type'] : MENU_CUSTOM_ITEM, ); - } - return $form; + if ($item['mid'] > 0) { + $form['menu']['delete'] = array( + '#type' => 'checkbox', + '#title' => t('Check to delete this menu item.'), + '#default_value' => $item['delete'], + ); + + $form['menu']['advanced'] = array( + '#type' => 'item', + '#value' => t('You may also edit the advanced settings for this menu item.', array('%edit' => url("admin/menu/item/edit/{$item['mid']}"))), + ); + } + } } /** -- cgit v1.2.3