Hello again,
I was wondering if you could help me figure this problem out. Currently I've got pages and other content types listed under menu categories but are not part of the menu that is trimmed. When these pages are viewed, the menu dissappears (expected behavior) but I was hoping that even through there is no active menu item, that the menu would still display based on the url.
I've been playing with the code and have been semi successful in getting it to work but only for the top level categories. To be truly helpful, this should be able to "find" an item down the tree.
I've added a new mode that "hides and but still shows the parent category" and have added this to the end of the if/else statements in the view case under the menu_trim_block() function
elseif ($mode == MENU_TRIM_ENABLED_SHOW_MENU_SECTION) {
//compare the parent menu url to the url path, if there is a
//partial match, show that section
$item = menu_get_item($delta);
foreach($item['children'] as $id => $mid) {
$top_category = menu_get_item($mid);
$top_path = drupal_get_path_alias($top_category['path']);
if($_SERVER['QUERY_STRING'] != null)
$url_path = explode("/",substr($_SERVER['QUERY_STRING'],2));
else
$url_path = explode("/",substr($_SERVER['PHP_SELF'],1));
if($top_path == $url_path[0]) {
$item = menu_get_item($mid);
$data['subject'] = check_plain($item['title']);
$data['content'] = theme('menu_tree', $mid);
break;
}
}
}
Would you have any ideas of how to efficiently traverse the menu tree and be able to pattern match based on the url to get into the sub menu items?
Any help would be appreciated.
Thanks!
Comments
Comment #1
keylope commentedSo I figured out the problem and hope that you can use this. Here's the breakdown of what I've done.
I created a new option in the admin dropdown that asks if you want to trim the menu but still show the parent menu (based on the url path).
Into the code, if the active trail is not found, create a trail based on the url path. This mimics the active trail and target the last id in the trail to be able to display any children.
When the appropriate menu section is rendered, check the mode and recreate the menu and all children and replace this newly created menu with the old menu created.
- This is done because since there is no "real" active item, any menu children are not expanded. I couldn't find good way to do this other than copying and modifying the menu_tree function to be able to target a specific menu id.
- The output isn't themed and since most theme functions only take an id, I wrapped the output by copying the theme_menu_tree function which just appends the ul tag and adds a class of menu.
Anyway, I'd love to get your opinion on this and see if it's something you would want to add to your project. That way I could get any other updates that you add in the future!
Thanks. Below is the code for menu_trim.module.
Comment #2
keylope commentedSheesh... already found a tweak.
This is to fix the case where there really is no trail, hide the menu, which is the current behavior of "show active menu".
Please add this code after line 114 (assigning variable $last_child_id):
Comment #3
dynv commentedThis is alot of code to go through, could you do a diff (-up) instead ? Would you mind explaining more the problem and the solution ?
Comment #4
dynv commentedComment #5
ar-jan commentedI've read what you've done (not the code though, that's a little over my head for now). I hope my question is relevant here; your node title says exactly what i'm trying to get done, so I guess so.
I want to have a Primary Link, in my case 'Publications', and clicking that should show all content items (nodes, in this case a node type 'Publication' made with CCK) that are Publications. Since I want to show many publications (info like title, author, year, journal, keywords; say about a hundred items) these should not be included as submenu items.
There are probably more ways than one to do this, so:
- Can I do this using taxonomy as my menu structure?
- Do I need to use Views to achieve this?
- Or should I look into using the code posted above?
I'm new to Drupal so please point me in the right direction, thanks in advance.
Arjan
Edit: Hmm, I suppose it should actually be a lot easier in my situation, I guess I could just make a (Primary) menu item and make the url point to the category: /category/publications/ (sorry ;-))
Comment #6
dynv commented@Arjan.M I understand you are unexperienced so this isn't flaming. First, does this issue has anything to do with the original issue ? If not, it's not appropriate to take over an issue and editing to remove your issue (saying something like wrong place) and set the title back like it was would be appropriate. Second, this sounds a lot like a support issue and this one is feature request. Usually support are done in the forum unless related to a specific module which can, but not always, be in a project issue. Lastly, there's a few concepts all rolled into one so in the right place for your issue, please untangle them and try to give specific examples.
Comment #7
david lesieur commentedI'm not convinced that there would be many use cases for this feature. It would also make the module harder to understand to users (even with its current features, it is already not as intuitive as I'd like it to be).