By klaasvanschelven on
Hi,
I would like to remove the "navigation" menu as a possible parent menu. I.e., when you select the "menu" options from "add/edit page" none of the navigation or submenu's should show up. The people who're actually going to add pages etc. will not want this and it will only confuse them.
Any advice is much appreciated.
Klaas
Comments
A workaround
I've adapted the following drupal code like so:
modules/menu/menu.module
contains a method menu_parent_options()
I've put a hack in that checks for the menu_title not being "navigation".
How should I go about moving this into a separate module?
interesting
Your questions made me wonder: shouldn't it be part of the Drupal core menu module to set different permissions for each menu? I think it would be a great feature, I think I will add a feature request in the issue tracker.
There is a module which already does something like that: http://drupal.org/project/menu_per_role. However, it has no stable version yet and it requires hacking in core files.
[update] The issue is here: http://drupal.org/node/241972. [/update]
Removing the admin menu from pages
Hi.
The menu settings per content type module removes the Admin menu very easily, plus offers other useful menu options, I'd highly recommend it! (Works with Drupal 5 and Drupal 6)
http://drupal.org/project/ctm
Martin
Thanks Martin
Thanks Martin, just what I was after and "Menu Settings per Content Type" has just made my mandatory module list ;)
Have you checked out the
Have you checked out the Forms API? http://drupal.org/node/37775
Because, you should be able to do this with a simple module that implements hook_form_alter()
You want to change the array used with $form['menu']['parent']['#options'] to show only the menus you want.
You could also hack into the menu.module itself - see this code from menu_form_alter().
Hope that is a little helpful.
Thanks - that's really
Thanks - that's really helpful. Will be my first module so it may take a while before I'll get to it... but will post results.
btw, I also stumbled across the following comment in the code:
So I'll have to set that variable somehow...
my solution
A few more lines but the original but at least it will allow for cleaner upgrades...
Hi, I need exactly what you
Hi,
I need exactly what you describe, too. But I'm an absolute newbie with drupal. What do I do with your codelines? Where do I add those, or are you still going to write a module for that?
Thanks!
cu,
Frank
Where to place code
Hi - looks very useful. Where does this code go? template.php? I'm having no luck with it.
Many thanks,
same issue
I think you place the code in the modules/menu/menu.admin.inc
i am not sure how?
i copied the entire code above and placed it at the bottom of the menu code.
it did not work -
i think that is because the menu module had ended and the code has to be embedded.
hmm actually no - i think i did it right ????
i obviously need help
there was away in the version 5.x
where the parent item did not show the navigation
Create a module for this
Just create a little module for this, it's very easy!
1. Create a subdir sites/all/modules/parentmenufilter/ (or /usr/share/drupal/modules/ or wherever you would like have your module).
2. In this subdir create parentmenufilter.info with
3. In the same subdir create a file parentmenufilter.module with the php-code from klaasvanschelven "my solution".
That's it. Go to drupals module page and enable the parentmenufilter module. Now when creating a page, navigation and secondary links won't show up as possible menu parents anymore (note there is a typo in the code referencing secondary-links twice. I guess it should be primary-links once).
Works like a charm
This was exactly what I needed and it works like a charm for all of my drupal 6.x sites. I've added it to my module tool belt for use in the future. Thanks for the snippet.
A Project Ricochet, Drupal Developers Team Member
My 4-step Module Solution
I have created a very simple module which allows you to hide the 'Navigation' menu from the 'Menu Settings' drop-down menu on the create/edit content forms.
I am not sure how to go about turning this into a proper module, and to be honest with you the code may not be bomb-proof at all. All I know is that it has been working for me and hopefully it will help someone else out too. Basically, use at your own risk, try it on a development site first before putting it on a live site and fingers crossed it works as well for you as it does for me.
If the following code is wrong or rubbish or massivly flawed please let me know! I am quite nervous to post this here! Can you tell?!
If you follow the instructions below, you should end up with a module which:
Step (1)
Create a directory in your sites/all/modules directory called 'mhn'
Step (2)
Create a file within the mhn directory you've just created called mhn.info
Add this code to it:
Step (3)
Create a file within the mhn directory called mhn.module
Add this code to it:
Step (4)
Head to the module page, activate the 'mhn' module and then head to the admin > site building > Menu Hide Navigation Settings page to choose which menus to show/hide. Also head to the admin > users > access contol page to specify which roles you want to be able to see all of the menus.
Thanks!
Code works :) but module doesn't :(
I tried making the module as you suggested but couldn't seem to get it working, my feeling is that it was something to do with permissions -- I always find them complicated so maybe it was me.
So what I did was take the code from the form_alter function and put it into my own 'glue' module and hard coded the mids I wanted to be available depending on $form_id. And by jove! it works like a treat :) It's exactly what I need. With all possible menu items being displayed there were literally hundreds to choose from -- a usability nightmare!
So big thanks to you baronmunchowsen.
Cool Cool.
Good stuff, glad it helped you somewhat. I should also say that if you're logged in as the primary user of the site (first account you create) then all the menus will appear, and whatever you setup to show/hide won't apply. I didn't get as far as to include this, because I'm using it to restrict access for people who have very limited permissions primarily.
Also, I've only tested this on drupal 5.
Also, please let me know what problems you encountered specifically and I'll see if I can help.
Just a little trick... Your
Just a little trick...
Your variable_get functions doesn't have a default paramter, and unless you have saved the settings once, the alter function can't find any settings per pid. Therefore, to make this excellent module work out of the box, hit save settings on the settings page after you have enabled the module.
Thanks for that... and it reminds me:
Step 2.5
Create a file within the mhn directory you've just created called mhn.install
Add this code to it:
Don't know whether having a .install file is mandatory, but I have one and didn't include it in my post above.
Can the default parameters be created in the .install file? I'll look into this and post back.
any news?
baronmunchowsen, did you every work some more on this code?
I could really use this functionality right now (using D5), but somehow I can't get it to work. No matter what i try, all menu items are still shown. it seems that the line
outputs all menu items.
Since the time that I wrote
Since the time that I wrote the post above I also discovered that you can control what menus are visible to the user on the node create/edit form via the admin > build > menu > settings page - removing the need in many cases for the use of this script. Perhaps look there first to see if that meets your requirements post back if not. Certainly in alot of simple cases this is all the functionality I really need.
Ta.
Using MenU settings
Only seems to let you choose one or all - have two menus I want to allow editors to use, leaving the navigation one hidden.
Exactly, that's what I found
Exactly, that's what I found too, the one-or-all option is too limited for my situation.
Here is an idea ...
I need to do the same thing, but inside organic groups (OG).
There is a module called OG Menu that makes it possible for each Organic Group to have its own totally separate menu tree. So I am thinking about modifying the part of the OG module that allow the creation of pages inside the OG. The goal is to make sure that the possible parent items will be limited to the ones that are under a menu that is assigned to the OG itself. If more than one menu is assigned to the OG, then I guess that I will display all of their items as possible parent item.
At first it will be hard coded. Then if the concept works, I will try to see if I can create a separate module that will add this functionnality (with hooks and stuff) without messing with the original OG module.
Does it make sense? Ideas? Advices?
Cheers
Live long ... and prosper!
RE: Here is an idea ...
asiby, did you ever find a solution for presenting only available Organic Group Menus for a node? I have a similar issue I'm trying to solve. We could code a custom module, but if you already found a solution, I'd love to hear it.