summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/menu.inc58
-rw-r--r--includes/theme.inc8
-rw-r--r--modules/menu/menu.module14
-rw-r--r--modules/system/system.module8
4 files changed, 69 insertions, 19 deletions
diff --git a/includes/menu.inc b/includes/menu.inc
index 9872e44b0..213834744 100644
--- a/includes/menu.inc
+++ b/includes/menu.inc
@@ -990,24 +990,56 @@ function menu_list_system_menus() {
* Return an array of links to be rendered as the Primary links.
*/
function menu_primary_links() {
- $tree = menu_tree_page_data('primary-links');
- $links = array();
- foreach ($tree as $item) {
- if (!$item['link']['hidden']) {
- $l = $item['link']['options'];
- $l['href'] = $item['link']['href'];
- $l['title'] = $item['link']['title'];
- $links[] = $l;
- }
- }
- return $links;
+ return menu_navigation_links('primary-links');
}
-
+
/**
* Return an array of links to be rendered as the Secondary links.
*/
function menu_secondary_links() {
- $tree = menu_tree_page_data('secondary-links');
+
+ // If the secondary menu source is set as the primary menu, we display the
+ // second level of the primary menu.
+ if (variable_get('menu_secondary_links_source', 'secondary-links') == 'primary-links') {
+ return menu_navigation_links('primary-links', 1);
+ }
+ else {
+ return menu_navigation_links('secondary-links', 0);
+ }
+}
+
+/**
+ * Return an array of links for a navigation menu.
+ *
+ * @param $menu_name
+ * The name of the menu.
+ * @param $level
+ * Optional, the depth of the menu to be returned.
+ * @return
+ * An array of links of the specified menu and level.
+ */
+function menu_navigation_links($menu_name, $level = 0) {
+ // Don't even bother querying the menu table if no menu is specified.
+ if (empty($menu_name)){
+ return array();
+ }
+
+ // Get the menu hierarchy for the current page.
+ $tree = menu_tree_page_data($menu_name);
+
+ // Go down the active trail until the right level is reached.
+ while ($level-- > 0 && $tree) {
+ // Loop through the current level's items until we find one that is in trail.
+ while ($item = array_shift($tree)) {
+ if ($item['link']['in_active_trail']) {
+ // If the item is in the active trail, we continue in the subtree.
+ $tree = empty($item['below']) ? array() : $item['below'];
+ break;
+ }
+ }
+ }
+
+ // Create a single level of links.
$links = array();
foreach ($tree as $item) {
if (!$item['link']['hidden']) {
diff --git a/includes/theme.inc b/includes/theme.inc
index d37aed16b..61344cfbd 100644
--- a/includes/theme.inc
+++ b/includes/theme.inc
@@ -733,6 +733,8 @@ function theme_get_settings($key = NULL) {
'logo_path' => '',
'default_favicon' => 1,
'favicon_path' => '',
+ 'primary_links' => 1,
+ 'secondary_links' => 1,
'toggle_logo' => 1,
'toggle_favicon' => 1,
'toggle_name' => 1,
@@ -741,6 +743,8 @@ function theme_get_settings($key = NULL) {
'toggle_mission' => 1,
'toggle_node_user_picture' => 0,
'toggle_comment_user_picture' => 0,
+ 'toggle_primary_links' => 1,
+ 'toggle_secondary_links' => 1,
);
if (module_exists('node')) {
@@ -1653,9 +1657,9 @@ function template_preprocess_page(&$variables) {
$variables['logo'] = theme_get_setting('logo');
$variables['messages'] = $variables['show_messages'] ? theme('status_messages') : '';
$variables['mission'] = isset($mission) ? $mission : '';
- $variables['primary_links'] = menu_primary_links();
+ $variables['primary_links'] = theme_get_setting('toggle_primary_links') ? menu_primary_links() : array();
+ $variables['secondary_links'] = theme_get_setting('toggle_secondary_links') ? menu_secondary_links() : array();
$variables['search_box'] = (theme_get_setting('toggle_search') ? drupal_get_form('search_theme_form') : '');
- $variables['secondary_links'] = menu_secondary_links();
$variables['site_name'] = (theme_get_setting('toggle_name') ? variable_get('site_name', 'Drupal') : '');
$variables['site_slogan'] = (theme_get_setting('toggle_slogan') ? variable_get('site_slogan', '') : '');
$variables['css'] = drupal_add_css();
diff --git a/modules/menu/menu.module b/modules/menu/menu.module
index 8a5f59e10..999e16761 100644
--- a/modules/menu/menu.module
+++ b/modules/menu/menu.module
@@ -856,14 +856,24 @@ function menu_configure() {
'#value' => t('The menu module allows on-the-fly creation of menu links in the content authoring forms. The following option sets the default menu in which a new link will be added.'),
);
- $authoring_options = menu_get_menus();
+ $menu_options = menu_get_menus();
$form['menu_default_node_menu'] = array('#type' => 'select',
'#title' => t('Default menu for content'),
'#default_value' => variable_get('menu_default_node_menu', 'navigation'),
- '#options' => $authoring_options,
+ '#options' => $menu_options,
'#description' => t('Choose the menu to be the default in the menu options in the content authoring form.'),
);
+ $secondary_options = array('secondary-links' => $menu_options['secondary-links'], 'primary-links' => $menu_options['primary-links']);
+ $form["menu_secondary_links_source"] = array(
+ '#type' => 'radios',
+ '#title' => t('Source for the secondary links'),
+ '#default_value' => variable_get('menu_secondary_links_source', 'secondary-links'),
+ '#options' => $secondary_options,
+ '#tree' => FALSE,
+ '#description' => t('Select what should be displayed as the secondary links . If %primary is choosen the children of the active primary menu link (if any) will be shown instead of the links in the %secondary menu.', array('%secondary' => $menu_options['secondary-links'], '%primary' => $menu_options['primary-links'])),
+ );
+
return system_settings_form($form);
}
diff --git a/modules/system/system.module b/modules/system/system.module
index e0152b5f1..460780709 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -1069,7 +1069,9 @@ function system_theme_default() {
'name',
'node_user_picture',
'search',
- 'slogan'
+ 'slogan',
+ 'primary_links',
+ 'secondary_links',
),
'stylesheets' => array(
'all' => array('style.css')
@@ -2365,7 +2367,9 @@ function system_theme_settings(&$form_state, $key = '') {
'node_user_picture' => t('User pictures in posts'),
'comment_user_picture' => t('User pictures in comments'),
'search' => t('Search box'),
- 'favicon' => t('Shortcut icon')
+ 'favicon' => t('Shortcut icon'),
+ 'primary_links' => t('Primary links'),
+ 'secondary_links' => t('Secondary links'),
);
// Some features are not always available