Hi
Is there any way to get Drupal to check the 'expanded' box for a menu item when you create it by adding a peice of content. With my default setup of Drupal, when I add a new page the options I have for a menu item for the page are the 'menu link title' the 'parent item' and the 'weight'. So when I create a new page I can create a new menu item on the fly, but I have no way of making it 'expanded'.
This means that I then have to go to /admin/build/menu-customize/primary-links for example and check the 'expanded' box if I want the menu to show up in a suckerfish menu.
This extra step is not too complicated for me, but I am not going to be managing the content on the site and I can see my client finding it odd that this extra step has to be taken to get the menu to show up. I can also see my client forgetting to do it in some months time and then wondering why his menu item is not appearing.
Is there any way to make menu items expanded by default, or to add the 'expanded' option to the 'create content' page
Thanks for any answers
Phil
Comments
hook_menu_link_alter
I think your best bet is to alter the menu link as it's being created.
http://api.drupal.org/api/function/hook_menu_link_alter/6
---------------------------------
Steven Wright
Slalom
Hi Steve Thanks for the link,
Hi Steve
Thanks for the link, I am not really techie enough to know what to do with it though. Do I just stick the code
into my page.tpl.php somewhere?
Expand menu by default
Hi
I am still not sure how to utilise the info on the page you have given me. I am not a coder so it is all a bit alien to me. Any help would be appreciated
Expand menu by default
Hi Phil,
I've stumbled upon your post with the same problem and i was unable to find a fix anywhere online. After taking a look at the menu.module file (sitewww/modules/menu/*)
I've have found you simply need to change the line:
339 // Set default values.
340 $node->menu = $item + array('link_title' => '', 'mlid' => 0, 'plid' => 0, 'menu_name' => $menu_name, 'weight' => 0, 'options' => array(), 'module' => 'menu', 'expanded' => 0, 'hidden' => 0, 'has_children' => 0, 'customized' => 0);
to
339 // Set default values.
340 $node->menu = $item + array('link_title' => '', 'mlid' => 0, 'plid' => 0, 'menu_name' => $menu_name, 'weight' => 0, 'options' => array(), 'module' => 'menu', 'expanded' => 1, 'hidden' => 0, 'has_children' => 0, 'customized' => 0);
Hope this helps,
Nathan
Nathan, you're a genius.
Nathan, you're a genius. Many thanks. This saved me hours of looking.
Don't hack core!
The better way of doing this is to create a custom module, which is what stevenc was suggesting (if you haven't done this before, read up here for D6 or here for D7).
Here is some code you can put in your D7 module to expand menu items for all new nodes. Make sure you replace HOOK with the name of your module:
For those on D6, here is a version that should work for you (haven't tested since I'm working on a D7 site):
Thanks for this, it may not
Thanks for this, it may not be the proper way of doing it, but has saved a lot of coding/searching around for an answer!
node insert definitely isnt the right way...
node insert definitely isnt the right way...
HOOK_node_insert didn't do
HOOK_node_insert didn't do the trick for me. I used:
This is still a valid
This is still a valid solution
Drupal 8 solution for expanded menus by default
There may be a hand ful of ways to do this for D8, but this is working for us:
You could probably also do something more general for all menu items in all menus, similar to other responses for d7 and d6. (Note this is untested)
Thanks jwilson3, this is
Thanks jwilson3, this is bugbear for me also, it's such a bummer the expanded toggle was removed from the menu overview page, one of the worst "UX improvements" in D7 and again made it into D8.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
D8 custom module
Got this error when trying to make a new page with a menu item after making a custom module i Drupal 8:
I made a folder in modules called: menu_auto_expand
file: menu_auto_expand.info.yml
file: menu_auto_expand.module
(installed the module)
What did I do wrong? Did I forget some part of the module or does the hook no longer work in D8?
Try this for Drupal 8
Try this for Drupal 8
Working code for D7
In a custom module, I included this:
This is tested and working. This hook cannot be used in a theme template.php file.
Of course that is extremely aggressive. You might consider doing something like:
That would limit it to the menu(s) you'd want (replace with correct menu names) and only parent items.