summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorGábor Hojtsy <gabor@hojtsy.hu>2007-08-20 18:26:41 +0000
committerGábor Hojtsy <gabor@hojtsy.hu>2007-08-20 18:26:41 +0000
commit6eaaa3c1b3779aa4a965232c97eb167f749ed09b (patch)
tree6578f22257d34c791efcda88ec9f031ce94d858a /includes
parentced08bf27a5c5dec209e2818b162bcf6ed80848b (diff)
downloadbrdo-6eaaa3c1b3779aa4a965232c97eb167f749ed09b.tar.gz
brdo-6eaaa3c1b3779aa4a965232c97eb167f749ed09b.tar.bz2
#160168 by kkaefer and pwolanin: restore lost Drupal 5 functionality of being able to set primary and secondary links differently
Diffstat (limited to 'includes')
-rw-r--r--includes/menu.inc58
-rw-r--r--includes/theme.inc8
2 files changed, 51 insertions, 15 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();