From ea53aad7c8ced499e397cbedfe1e0cce205c071f Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Thu, 3 Nov 2005 19:33:37 +0000 Subject: - Patch #22215 by Richard Archer: refactored primary and secondary links. Deprecates the primary_links module. This patch was much needed. Thanks Richards! NOTE: if some themers could investigate if there is room for improvement with regard to theming, that would be awesome. --- modules/menu.module | 48 +++++++++++++++++++++++++++++++++ modules/menu/menu.module | 48 +++++++++++++++++++++++++++++++++ modules/system.module | 63 -------------------------------------------- modules/system/system.module | 63 -------------------------------------------- 4 files changed, 96 insertions(+), 126 deletions(-) (limited to 'modules') diff --git a/modules/menu.module b/modules/menu.module index bed29b92a..e0a4b23c6 100644 --- a/modules/menu.module +++ b/modules/menu.module @@ -47,6 +47,11 @@ function menu_menu($may_cache) { 'callback' => 'menu_reset', 'access' => user_access('administer menu'), 'type' => MENU_LOCAL_TASK); + + $items[] = array('path' => 'admin/settings/menu', + 'title' => t('menus'), + 'callback' => 'menu_configure', + 'access' => user_access('administer menu')); } return $items; @@ -84,7 +89,50 @@ function menu_help($section) { return t('

Enter the name for your new menu. Remember to enable the newly created block in the %blocks administration page.

', array('%blocks' => l(t('blocks'), 'admin/block'))); case 'admin/menu/item/add': return t('

Enter the title, path, position and the weight for your new menu item.

'); + case 'admin/settings/menu': + return t('

Customize the menu settings.

'); + } +} + + +/** + * Menu callback; presents menu configuration options. + */ +function menu_configure() { + $menu = menu_get_menu(); + + $primary_options[0] = t('No primary links'); + foreach ($menu['items'][0]['children'] as $mid) { + $primary_options[$mid] = $menu['items'][$mid]['title']; } + + $form['settings_links'] = array('#type' => 'fieldset', '#title' => t('Primary links settings')); + $form['settings_links']['intro'] = array( + '#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 + ); + + $secondary_options[0] = t('No secondary links'); + foreach ($menu['items'][0]['children'] as $mid) { + $secondary_options[$mid] = $menu['items'][$mid]['title']; + } + + $form['settings_links']['menu_secondary_menu'] = array( + '#type' => 'select', + '#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.') + ); + + return system_settings_form('menu_configure', $form); } /** diff --git a/modules/menu/menu.module b/modules/menu/menu.module index bed29b92a..e0a4b23c6 100644 --- a/modules/menu/menu.module +++ b/modules/menu/menu.module @@ -47,6 +47,11 @@ function menu_menu($may_cache) { 'callback' => 'menu_reset', 'access' => user_access('administer menu'), 'type' => MENU_LOCAL_TASK); + + $items[] = array('path' => 'admin/settings/menu', + 'title' => t('menus'), + 'callback' => 'menu_configure', + 'access' => user_access('administer menu')); } return $items; @@ -84,7 +89,50 @@ function menu_help($section) { return t('

Enter the name for your new menu. Remember to enable the newly created block in the %blocks administration page.

', array('%blocks' => l(t('blocks'), 'admin/block'))); case 'admin/menu/item/add': return t('

Enter the title, path, position and the weight for your new menu item.

'); + case 'admin/settings/menu': + return t('

Customize the menu settings.

'); + } +} + + +/** + * Menu callback; presents menu configuration options. + */ +function menu_configure() { + $menu = menu_get_menu(); + + $primary_options[0] = t('No primary links'); + foreach ($menu['items'][0]['children'] as $mid) { + $primary_options[$mid] = $menu['items'][$mid]['title']; } + + $form['settings_links'] = array('#type' => 'fieldset', '#title' => t('Primary links settings')); + $form['settings_links']['intro'] = array( + '#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 + ); + + $secondary_options[0] = t('No secondary links'); + foreach ($menu['items'][0]['children'] as $mid) { + $secondary_options[$mid] = $menu['items'][$mid]['title']; + } + + $form['settings_links']['menu_secondary_menu'] = array( + '#type' => 'select', + '#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.') + ); + + return system_settings_form('menu_configure', $form); } /** diff --git a/modules/system.module b/modules/system.module index 9fa32b0a0..6454945ec 100644 --- a/modules/system.module +++ b/modules/system.module @@ -1043,11 +1043,6 @@ function system_theme_settings($key = '') { // System wide only settings. if (!$key) { - // Menu settings - - $form['primary_links'] = system_navigation_links_form('primary', 'Primary'); - $form['secondary_links'] = system_navigation_links_form('secondary', 'Secondary'); - // Toggle node display. $node_types = module_invoke('node', 'get_types'); if ($node_types) { @@ -1066,8 +1061,6 @@ function system_theme_settings($key = '') { 'toggle_name' => t('Site name'), 'toggle_slogan' => t('Site slogan'), 'toggle_mission' => t('Mission statement'), - 'toggle_primary_links' => t('Primary links'), - 'toggle_secondary_links' => t('Secondary links'), 'toggle_node_user_picture' => t('User pictures in posts'), 'toggle_comment_user_picture' => t('User pictures in comments'), 'toggle_search' => t('Search box'), @@ -1117,62 +1110,6 @@ function system_theme_settings($key = '') { } -function system_navigation_links_form($type, $utype) { - $settings = theme_get_settings(''); - $value = $settings[$type . '_links']; - - if (!is_array($value)) { - $value = array(); - } - // Increment the link count, if the user has requested more links. - if (variable_get($type . '_links_more', false)) { - variable_del($type . '_links_more'); - variable_set($type . '_link_count', variable_get($type . '_link_count', 5) + 5); - } - - // Get the amount of links to show, possibly expanding if there are more links defined than the count specifies. - $count = variable_get($type . '_link_count', 5); - $count = ($count > sizeof($value['link'])) ? $count : sizeof($value['link']); - - if (variable_get($type . '_link_count', 5) != $count) { - variable_set($type . '_link_count', $count); - } - $form = array( - '#type' => 'item', '#title' => t('_TYPE_ link settings', array('_TYPE_' => $utype)), '#theme' => 'system_navigation_links_form', - '#description' => t('You can specify your _TYPE_ links here, one link per line.
The link text field is the text you want to link.
The url field is the location the link points to.
The description field is an optional description of where the link points.', array('_TYPE_' => $type)) - ); - - $form['#tree'] = TRUE; - - for ($i = 0; $i < $count; $i++) { - foreach (array('text', 'link', 'description') as $field) { - $form[$field][$i] = array('#type' => 'textfield', '#default_value' => $value[$field][$i], '#size' => 15, '#maxlength' => 90); - } - } - - $form[$type . '_links_more'] = array( - '#type' => 'checkbox', '#title' => t('I need more _TYPE_ links.', array('_TYPE_' => $type)), '#default_value' => FALSE, - '#description' => t('Checking this box will give you 5 additional _TYPE_ links.', array('_TYPE_' => $type)) - ); - return $form; -} - -function theme_system_navigation_links_form(&$form) { - $header = array(t('link text'), t('url'), t('description')); - foreach (element_children($form['text']) as $key) { - $row = array(); - $row[] = form_render($form['text'][$key]); - $row[] = form_render($form['link'][$key]); - $row[] = form_render($form['description'][$key]); - $rows[] = $row; - - } - $output = theme('table', $header, $rows); - $output .= form_render($form); - return $output; -} - - function search_box() { $form['#action'] = url('search'); $form['keys'] = array('#type' => 'textfield', '#size'=> 15, '#value' => '', '#attributes' => array('alt' => t('Enter the terms you wish to search for.'), 'class' => 'form-text')); diff --git a/modules/system/system.module b/modules/system/system.module index 9fa32b0a0..6454945ec 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -1043,11 +1043,6 @@ function system_theme_settings($key = '') { // System wide only settings. if (!$key) { - // Menu settings - - $form['primary_links'] = system_navigation_links_form('primary', 'Primary'); - $form['secondary_links'] = system_navigation_links_form('secondary', 'Secondary'); - // Toggle node display. $node_types = module_invoke('node', 'get_types'); if ($node_types) { @@ -1066,8 +1061,6 @@ function system_theme_settings($key = '') { 'toggle_name' => t('Site name'), 'toggle_slogan' => t('Site slogan'), 'toggle_mission' => t('Mission statement'), - 'toggle_primary_links' => t('Primary links'), - 'toggle_secondary_links' => t('Secondary links'), 'toggle_node_user_picture' => t('User pictures in posts'), 'toggle_comment_user_picture' => t('User pictures in comments'), 'toggle_search' => t('Search box'), @@ -1117,62 +1110,6 @@ function system_theme_settings($key = '') { } -function system_navigation_links_form($type, $utype) { - $settings = theme_get_settings(''); - $value = $settings[$type . '_links']; - - if (!is_array($value)) { - $value = array(); - } - // Increment the link count, if the user has requested more links. - if (variable_get($type . '_links_more', false)) { - variable_del($type . '_links_more'); - variable_set($type . '_link_count', variable_get($type . '_link_count', 5) + 5); - } - - // Get the amount of links to show, possibly expanding if there are more links defined than the count specifies. - $count = variable_get($type . '_link_count', 5); - $count = ($count > sizeof($value['link'])) ? $count : sizeof($value['link']); - - if (variable_get($type . '_link_count', 5) != $count) { - variable_set($type . '_link_count', $count); - } - $form = array( - '#type' => 'item', '#title' => t('_TYPE_ link settings', array('_TYPE_' => $utype)), '#theme' => 'system_navigation_links_form', - '#description' => t('You can specify your _TYPE_ links here, one link per line.
The link text field is the text you want to link.
The url field is the location the link points to.
The description field is an optional description of where the link points.', array('_TYPE_' => $type)) - ); - - $form['#tree'] = TRUE; - - for ($i = 0; $i < $count; $i++) { - foreach (array('text', 'link', 'description') as $field) { - $form[$field][$i] = array('#type' => 'textfield', '#default_value' => $value[$field][$i], '#size' => 15, '#maxlength' => 90); - } - } - - $form[$type . '_links_more'] = array( - '#type' => 'checkbox', '#title' => t('I need more _TYPE_ links.', array('_TYPE_' => $type)), '#default_value' => FALSE, - '#description' => t('Checking this box will give you 5 additional _TYPE_ links.', array('_TYPE_' => $type)) - ); - return $form; -} - -function theme_system_navigation_links_form(&$form) { - $header = array(t('link text'), t('url'), t('description')); - foreach (element_children($form['text']) as $key) { - $row = array(); - $row[] = form_render($form['text'][$key]); - $row[] = form_render($form['link'][$key]); - $row[] = form_render($form['description'][$key]); - $rows[] = $row; - - } - $output = theme('table', $header, $rows); - $output .= form_render($form); - return $output; -} - - function search_box() { $form['#action'] = url('search'); $form['keys'] = array('#type' => 'textfield', '#size'=> 15, '#value' => '', '#attributes' => array('alt' => t('Enter the terms you wish to search for.'), 'class' => 'form-text')); -- cgit v1.2.3