Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This is a question for template_preprocess_page
.
I don't understand why the nav links pulled in again using menu_tree_page_data
. This function will post disabled items.
Why don't we just the links that are already in $variables['primary_menu']
and $variables['secondary_menu']
?
Comment | File | Size | Author |
---|---|---|---|
#39 | bootstrap-fix-default-menus-1460508-39.patch | 3.96 KB | natted |
#39 | menu-changes.png | 66.33 KB | natted |
#34 | bootstrap-navigation-fix-1860142-3.patch | 2.6 KB | natted |
#33 | bootstrap-navigation-fix-1860142-3.patch | 2.6 KB | natted |
#31 | bootstrap-navigation-region-1460508-31.patch | 4.7 KB | natted |
Comments
Comment #1
gagarine CreditAttribution: gagarine commentedMarked as duplicate #1446170: Main menu show disable menu link.
Look at menu_navigation_links how the hide disabled menu.
But instead of making your own system it will be certainly possible to overwrite theme_menu_link .
Comment #2
gagarine CreditAttribution: gagarine commentedI find than menu in block use correct theme function. So the problem is only if you use the main_menu and secondary_menu variable in your template (in fact $secondary_nav and $primary_nav with this theme).
Comment #3
makangus CreditAttribution: makangus commentedI am subtheming twitter_bootstrap, in the subtheme i just put the main_menu back to default and add in the class .nav and things should work relatively fine.
There are a few issues in theme.inc that comes with twitter_bootstrap,
On the main menu, the h2 is inside the ul, the li don't have classes on them, etc. If anyone is interested, I can fix up a patch that makes it use the default drupal theme function links__system_main_menu to create the main menu.
Comment #4
makangus CreditAttribution: makangus commentedPatch to make the main menu use the default drupal theme function links__system_main_menu. It fixes the problems introduced in twitter_bootstrap_twitter_bootstrap_links() like invalid markup of h2 in ul, missing active and other classes on li and a.
The only visual difference I can see is now the active class triggers the css for .navbar .nav .active
Comment #5
gagarine CreditAttribution: gagarine commentedWe should delete twitter_bootstrap_menu_navigation_links function.
Also perhaps take a look at https://github.com/mpezzi/bootstrap.
Comment #6
lathos CreditAttribution: lathos commentedmakangus' patch (#4) fixes another problem - menus are not properly localized in the current version of twitter_bootstrap - but it means that multi-level menus no longer work.
Comment #7
jmoughon CreditAttribution: jmoughon commentedThanks for this I patched this on my subtheme
Comment #8
alexku CreditAttribution: alexku commentedmakangus' patch (#4) has also fixed a problem we had with discarding purl in some menus.
If the plan will be to keep using twitter_bootstrap_menu_navigation_links I have a patch for it to fix the purl issue and the problem mentioned by lathos (#6).
Comment #9
barryvdh CreditAttribution: barryvdh commentedI agree, the navigation is pretty useless, active trails are not applied, hidden items are being displayed etc. I used the menu blocks module, works a lot better.
Comment #10
liminu CreditAttribution: liminu commentedI try patch number 4 but not work, how can i disable the bootstrap navigation?
Comment #11
gagarine CreditAttribution: gagarine commented#4 do not work for sub menu.
Comment #12
zmove CreditAttribution: zmove commented#4 Should be in need review for a future commit as its waiting since April.
Comment #13
gagarine CreditAttribution: gagarine commentedas say in #11 this do not works if we have submenu.
Comment #14
natted CreditAttribution: natted commentedWell, to solve this issue we need to decide:
1. Do we want submenu's to work?
If so, then I think we need to continue using menu_tree don't we?
The original issue complains that the disabled items are being shown. I've posted a patch in:
#1825790: Menu still shows "disabled" menu items
So, that negates the initial complaint...
The other is sub menu items... I started playing with that.. it isn't perfect but my initial test patch is in:
#1706180: dropdown for main menu?
Happy for feedback though, I'm sure there may be better methods to resolve these issues.
Comment #15
gagarine CreditAttribution: gagarine commentedWe can use main-menu block in a region "top bar" instead of the primary_nav. Poeple than don't want this top bar should be able t just drag the main-menu in an other region...
What do you think?
Or something like that:
Comment #16
andregriffin CreditAttribution: andregriffin commentedComment #17
andregriffin CreditAttribution: andregriffin commentedComment #18
natted CreditAttribution: natted commentedComment #19
zmove CreditAttribution: zmove commentedIn fact, the best thing would be to completely disable $primary_nav and $secondary_nav page variables which are ancient ghost of Drupal 5 menu system and use the menu blocks instead which are far more flexible.
Same for search
Comment #20
frankbaele CreditAttribution: frankbaele commentedmaybe we should just remove the vars and replace them by a region
Comment #21
frankbaele CreditAttribution: frankbaele commentedok added a patch that removes the vars and adds a region instead
Comment #22
frankbaele CreditAttribution: frankbaele commentedi also think this patch is somhow related to http://drupal.org/node/1706180 and if accepted should be commited together
Comment #24
frankbaele CreditAttribution: frankbaele commentedok redone the patch, strange that it fails
Comment #25
frankbaele CreditAttribution: frankbaele commentedComment #27
frankbaele CreditAttribution: frankbaele commentedremoved also all the search form settings and theming
Comment #28
frankbaele CreditAttribution: frankbaele commentedComment #29
natted CreditAttribution: natted commentedThanks Frank.
I've converted one site of mine to using region for the main menu, so I'll just check and see how your patch affects it.
Comment #30
natted CreditAttribution: natted commentedIt works. Anyone see any problems having the nested region?
I understand the navigation region though, otherwise we'd need to include a custom region--header.tpl.php template file (which is what I did with another site to get menu blocks).
The patch really should be combined with #1706180: dropdown for main menu? to make it worthwhile. If I have time in a moment, I'll combine the two.
Comment #31
natted CreditAttribution: natted commentedMinor adjustment to capitalization, same patch as #27 otherwise.
Comment #32
natted CreditAttribution: natted commentedTo move things along I have committed Frank's patch to 2.x-dev.
Menus can be added to the Navigation region via Blocks administration. It's recommended to set the menu block title to
<none>
If you want to float a menu right (e.g. user-menu), then it is just a case of adding a theme override to include
pull-right
, such as:Comment #33
natted CreditAttribution: natted commentedSo, the latest commit did cause an issue #1860142: Notice: Undefined index: navigation in include() (line 23 of [...]/themes/bootstrap/templates/page.tpl.php).
As an interim (patch attached), I've added the original primary_nav and secondary_nav options back for those who don't have anything assigned to Navigation (or if Navigation doesn't exist).
Comment #34
natted CreditAttribution: natted commentedFlagged for testing.
Comment #35
natted CreditAttribution: natted commented#1860142: Notice: Undefined index: navigation in include() (line 23 of [...]/themes/bootstrap/templates/page.tpl.php) is fixed but this means the original issue in #1 is still present.
I'll propose a new patch over the weekend to resolve this once and for all.
Comment #36
natted CreditAttribution: natted commentedOk, so I've looked into this for quite some time. I'm going to summarise the issue below.
The original issue asks:
I wasn't around when the theme was developed, however the #1 reason I can see for including primary_nav and secondary_nav is to include dropdown and submenu support. Perhaps due to bugs, this may or may not have been obvious when this issue was raised. Disabled items are no longer displayed. #1825790: Menu still shows "disabled" menu items
To do this, people would need to be able to render dropdowns and submenus via a theme function (ie. bootstrap_links). It appears this doesn't work 100%. If someone wants to help fix that, then perhaps we can remove $primary_nav and $secondary_nav.
To close this issue I propose:
1. bootstrap_preprocess_page
Change bootstrap_preprocess_page to populate $primary_nav and $secondary_nav in the same way menu blocks would populate it, using
menu_tree
(similar to code posted by gargarine in #15). This will ensure that the main menu will support dropdowns and submenus as soon as the theme is installed - no need to assign blocks to regions unless people choose.2. page.tpl.php
Keep $primary_nav and $secondary_nav menu's as defaults in page.tpl.php. If people want to remove them, they can easily untick Main Menu and Secondary Menu in the theme settings and assign block menus to the Navigation region. The Navigation region would remain, so out of the box it would be rendered as:
$primary_nav + [region: navigation ] + $secondary_nav
Search will need to be assigned to Navigation via blocks. Turning off Main menu and Secondary Menu in the theme settings would just leave people with the Navigation region.
3. In future we may be able to remove $primary_nav and $secondary_nav
At some later date we can consider removing $primary_nav and $secondary_nav completely. I think to do so, we need to ensure a theme function is available to render the Drupal main_menu and secondary_menu's with dropdown + submenu support, so that it works out of the box. (We can create a new issue for this).
Hope all this makes sense. I'll attach a patch as soon as I can.
Any problems/issues? Let me know.
Comment #37
andregriffin CreditAttribution: andregriffin commentedThis is how I handled dealing with default menus vs. block in navigation region in the Framework theme. This might be a useful way of handling the choice in the page.tpl
Comment #38
frankbaele CreditAttribution: frankbaele commented+1 for natted summary and solution, got my ok
Comment #39
natted CreditAttribution: natted commentedAlright, so here is the patch I am proposing:
What has changed?
1. bootstrap_preprocess_page
menu_tree__primary
andmenu_tree__secondary
Why change this?
The default menus now render out of the box in the same way as the menu block's, so they automatically should support dropdown menus and nested submenus. I've included the theme wrapper functions in case people want a simpler way to override the HTML wrapper for the menu's (allowing to change the style of menu button in a subtheme etc).
Default main menu theme wrapper:
Default secondary menu theme wrapper:
As mentioned above: page.tpl.php renders navigation as follows:
$primary_nav + [region:navigation] + $secondary_nav
This means, if you don't want $primary_nav and $secondary_nav, then just disable them in the theme settings and they are gone. You can then just use the Navigation region to assign block menu's. If you want a third menu, just assign it via blocks to Navigation... mix and match!
Out of the box, this is how it looks:
I'm sure the first think people will say is.. "the right hand user-menu is not a dropdown... ". So, to turn it into a dropdown you can either edit the menu and add a new item to nest the links .. e.g:
Or, the user might just decide to override their subtheme (this is just an example...):
Any thoughts? I've tested this and it appears to be working. I guess others can tell me if this change is worthwhile...
Like I mentioned, longer term - we may be able to remove $primary_nav and $secondary_nav if we can improve the bootstrap theme functions. I think though, we can create a separate issue for that if we feel it is really important to do so.
Comment #40
natted CreditAttribution: natted commentedComment #41
andregriffin CreditAttribution: andregriffin commentedGreat work, natted. +1 from me.
Comment #42
frankbaele CreditAttribution: frankbaele commentedcommited http://drupalcode.org/project/bootstrap.git/commit/e5db762
Comment #43
frankbaele CreditAttribution: frankbaele commentedand also tested it couple of times, works like a charm now