Hi,

I just switched from WordPress (garbage) to Drupal and I'm ecstatic that I finally found a great CMS/blogging platform that works properly and doesn't have improperly ported themes that wordpress and the rest pass around like cheap whores, leaving things out each time.

The only problem/confusion that I'm having is on one of my menus I have a child menu. I would expect the child menu to show up only when I click on the parent menu link however it does not show up at all. The child shows up fine if I set the "Expand Always" checkbox on the parent menu, but how do I get it to only expand when active? Is that a setting that I've missed somewhere?

Comments

raspberryman’s picture

Hi DssTrainer,

Check out your /admin/menu/ page. Do you have two or more menu items that point to the same path?
The most common cause I've seen for this behavior is having two or more menu items pointing to the same content (i.e., two or more links pointing to a particular node).

I think this is how it works...

I like to think of the Drupal menu system has being very similar to the traditional concept of a sitemap. A traditional sitemap lists every link available on the site, usually grouped together.

  • link
    • link
    • link
  • link
    • link

The menu system is such a list of links, but this time with your Drupal paths (such as nodes).

  • [node/1]
    • [node/3]
    • [node/4]
  • [node/2]
    • [node/5]

It is key to differentiate between menu items and paths. Drupal's menu system (or sitemap, as I like to think of it) is based on paths. Menu items are more or less just labels for paths. Parent/child relationships are based on paths, not menu items.

A common source of the behavior you are noticing is having two menu items pointing to one path, ie:

  • [node/1]
    • [node/3]
    • [node/4]
  • [node/4]
    • [node/5]

So now Drupal has to decide which menu to display: the child [node/4], or the parent [node/4]. Which to display as currently selected? Which to display as expanded? How can the child of [node/1] also be the sibling of [node/1]?

Well, from what I can tell, Drupal will determine this based on ranking in the menu system. Those earlier in the menu will be chosen. So in the example, the child [node/4] is displayed. The parent [node/4] is all but ignored and thus not expanded. So:

  • [node/1]
    • [node/3]
    • [node/4] DISPLAYED
  • [node/4] IGNORED, and thus not expanded
    • [node/5]

Let me know if this helps, and good luck!!!

DssTrainer’s picture

Thank you for your detailed reply :) I understand what you are saying. I will check that out to see if it is getting called anywhere else. I'll even try deleting it all together and creating a new link to see if that fixes it since Im sure a new link wouldn't be in 2 spots yet.

Thanks again!

raspberryman’s picture

Hey DssTrainer,

Did this resolve your issue?

Please reply so that others who run across this thread can learn from it.

steverippl’s picture

I had exactly the same problem and it was because I had another link to that same top page. It seems as though the order in the db is what counts, whichever link was put in first will be the one to take precedence.

idropper-1’s picture

Child items DO show up when I force navigate to a child page via content manager.

But they don't pop down from the parent menu, nor do they appear when in the parent page. Of course I can force them to be there with "show expanded" but that wrecks the popdown menu.

I tried cleaning the menu of conflicting and misordered items as evo said (thanks evo - that helped me understand the Way of Drupal). I even tried linking to the nodes directly in the menu (rather than aliases) but still no joy.

Is this true for anyone else?

davidbl’s picture

My only difference is that I created two custom menus: the first one with 1 parent and 10 child elements is working perfectly, but not so the second one with 1 parent and just 2 child elements (they appear if I check "expand" in parent, but not otherwise, anyway I need the same behaviour than in my first custom menu -the 1-10 elements one-)
I have double checked that there are no duplicates in my neither in my custom or navigation menus: both checked that there are no duplicate names nor paths but still no luck.
I will reset the menus to the default state and will rebuild my custom menus (it will take me a while to rebuild the first custom menu).
I will come back here to say if I had success.

davidbl’s picture

After double-checking that I had no repeated links in any other menus (I found one directing to the forums, but wich did not duplicate in the menu I had trouble with, however I deleted it just in case...) I deleted the former malfunctioning menu items from the bottom to the top elements one by one: first the children then the parent element then the menu.
Afterwards, I created a different menu with different names and different links and started modifiying one at a time in order test each element one by one to spot the troubling one:

One (parent)
-Two (=child 1)
-Three (= child 2)

Then I renamed and changed the link on the parent

News (parent)
-Two (=child 1)
-Three (= child 2)

Then I renamed and changed the link on the children one at a time, so first:

News (parent)
-Center (=child 1)
-Three (= child 2)

and then

News (parent)
-Center (=child 1)
-General (= child 2)

And that did it. Don´t know exactly why, but now it works.

gatezone’s picture

Same issue... I don't see any duplicates between menus because they are all new items. I'm not sure why it should be such a disabling issue even if there were duplicates? Has anyone else found a slightly more consistent way to address this? TIA GZ

rileyhuff’s picture

riley-huff

I was able to fix this problem. In my case the parent item was using a absolute url, from within drupal. I edited the parent item to have a relative url and it worked!

Anonymous’s picture

Just dealt with this issue... and Steve's solution seems to be correct. I had a Primary Links menu item that pointed to the same page as a custom menu link, so the custom menu link wouldn't expand. I deleted the Primary Links menu item, verified that the custom menu link worked properly with the expand and collapse, then rebuilt the Primary Links menu item. All works well now. Thanks for the tip.

Happy day,
Anne

stinky’s picture

I've deleted my Primary Links menu and rebuilt a new custom menu, but my list won't expand unless I force expand it :(

stinky’s picture

Basically you can't have any duplicates in your default Navigation and your Custom Nav. I created a custom nav and then moved items from the default Nav to custom nav.

gs12345’s picture

What do you do with locked items, like my account or my blog? You can't deactivate those or move them anywhere. They just keep blocking the custom menu.

zb’s picture

Hello.
Thanks for your input to this subject. I was hoping you or maybe someone else would point a newbie in the right direction.
I think my problem is that I don't understand the whole "node/add" thing in the path. Or it is that I'm having trouble diff between
menu item and path. (btw - I currently have no related primary links)

Seems I always use "node/add" in the path. In most cases, I can see the node number on the resulting page but, then I've actually seen "node/add" in the URL and get confused. In the admin I can clearly see the parent and the child but, when expanded is not checked, I get no result - it won't expand and I can find the related child article.

Any suggestions?

tx,
zb

oriol_e9g’s picture

Same problem with drupal 5.2. I check that i have not any duplicate url :(

waltWright’s picture

Moving my recent post here because it is same issue. This has either got to be a bug (who'll take it on?) or poor documentation (we need somebody to explain and contribute). Thanks in advance!

Ok, 4 months now of reading the site cover-to-cover and lots of experimenting, but...

Can somebody explain exactly how the Expanded attribute works in default menu module?
Better yet - please refer me to a comprehensive document that comprehensively shows the use of the Expanded property.
What I want is so basic, but I can't get it to work reliably and confidently. What is needed is a standard heirarchical menu:

1. Navigation menu, add four items at highest level, with "Navigation" as parent; e.g. Item1, Item2, Item3, Item4

2. Each menu has several menu items below the first tier, e.g. Item1-1, Item1-2, Item1-3, Item1-4

3. Some menu items go down one level deeper, e.g. Item2-3-1, Item2-3-2

4. The menu items are hierarchical and exact replica of the taxonomy hierarchy that I am using

5. Most of the menu items point directly to a custom view using the standard Views module

6. Other items point to a simple temporary page node with body = "Temporary page"

  • While constructing sample stories and constructing the views, I set the Expanded attribute to "Yes" on all but one of the menu items because the menu would stay collapsed for three of the four menu items that were children of Navigation. I figured that maybe there was some requirement to have content prepared or else the menu wouldn't expand - but not sure.
  • At first, I created a view for each of the four highest level menu items and then set the Expanded attribute to "No" and the menus worked fine.
  • Then I replaced each of the 4 highest level menu items with blank pages (did not actually delete the views, but the url seems to favor the page over a view).
  • And then only one of the menu items worked correctly with the expand/collapse. What's really confusing is that that one that now works is completely different than the one that was working early on.
    This has got to be simple, but no docs, no answers, no logic. Thanks for the help!
  • waltWright’s picture

    NICE Menus! What a great module. Absolutely zero setup time and the menus collapse and expand like magic. Never looking back.

    plorant’s picture

    I got the same problem.
    (no path duplication, but not expandable menus, may be deleted primary links caused the problem)
    Tried nice menu module, but admin/blocks/nice_menu/configure goes out to the white emtiness (on every default theme)...
    Not ready for 5.2, and I tink this problem is on it only.

    (On 4.7 nice menu is a great module, I agree.)

    waltWright’s picture

    See the bottom of this thread: http://drupal.org/node/147404

    - it shows how to split the primary menu (in the header) from the secondary (in the left or right column). Expanded menus work properly for some reason when I couldn't get them to work otherwise.

    cwgordon7’s picture

    This isn't quite the same issue, but I also found that the drupal menu's system of opening the page of a parent item (default collapsed) in order to see the children item was unintuitive- the average user expects the menu to expand, not to go to a new page and then expand. I tried nice_menus for a while, but it didn't work as well as I expected, and the way that it disappeared without delay when your mouse moved off the menu created usability issues. So, I created a new module, called fieldset menus in order to simply expand parent items- not change the page. I suggest that, if you're having trouble with drupal's default menu system, you try this module.

    -cwgordon7

    scafmac’s picture

    I've found that if there are any encoded characters in the path, then they will not expand properly. For example I was using a view & argument for a page - let's say the view url was services and the argument was community members. I thought I was being smart by setting the path for the menu to:
    services/community%20members

    Notice the %20 - an encoded space. Turns out drupal is happier with a real space:
    services/community members

    FWIW

    seddonym’s picture

    See my bug report here for a detailed examination of my issues with this.

    In summary, I found that using the Menu API wasn't very good for expanding items (in Drupal 5.3 at least). You could use it to create items but then you had to comment out the code to get the expansion working. Still trying to resolve it but I'll probably circumvent the menu API and just use db_query().

    darumaki’s picture

    This is interesting, I'm trying to do just the opposite, child menus appear under their parent but I don't want them too, i'm using related links to list subpages in a different block

    cosmichippy777’s picture

    Hello there,

    I read your bug report and can (almost understand).

    A few questions...

    1. How can I use db_query to get around the problem with drupal api?

    2. Where exactly do I use it (as in where is the code in question - I am new to drupal and having problems finding some of the code).

    I have 3 items in primary menu, each of which should expand into 3 items in secondary menu. Should not be so hard but this is stopping me uploading my site now!

    Please see....
    http://drupal.org/node/198042

    For more detailed explanation.

    Thanks!

    Kind regards
    NICK

    seddonym’s picture

    Hi Nick,

    Here is the code I used to get around the problem. It specifically builds child menus dynamically by inserting records directly into the menu table. A bit hackish, but what can you do when the API is malfunctioning?

    
    function birgitmod_perm() {
        return array('rebuild birgit menus');
    }
    
    function birgitmod_menu($may_cache) {
        if ($may_cache) {
            $items[] = array( 
                'title' => t('Rebuild Birgit Menus'),
                'path' => 'admin/build/menu/rebuild',
                'callback' => 'birgitmod_rebuild',
                'access' => user_access('rebuild birgit menus'), 
            );
            return $items;
        }
    
    }
    
    
    function birgitmod_nodeapi(&$node, $op) {
        //If something that affects the dynamic menus has been changed,
        //correct the dynamic menus.  Check for insert/delete/update actions 
        //first as that should happen much less often than viewing of 
        //homecollection/womenswear items
        if (($op == 'insert' || $op == 'delete' || $op == 'update')) {
            if ($node->type == 'homecollection_item' 
             || $node->type == 'homecollection_designer'
             || $node->type == 'homecollection_category') {
                    
                $collectionMenus = new Homecollection();             
            
            } else if ($node->type == 'womenswear_item'
             || $node->type == 'womenswear_designer'
             || $node->type == 'womenswear_category') {
            
                $collectionMenus = new Womenswear();
            }    
           
            $collectionMenus->purge();
            $collectionMenus->build_all();
            drupal_set_message('Menus rebuilt.');
        } 
    }
    
        function birgitmod_rebuild() {
        
            $menu_items[] = new Homecollection();
            $menu_items[] = new Womenswear(); 
                
            foreach ($menu_items as $menu_item) {
                
                //Delete all menu items which begin with womenswear/ or homecollection/
                $menu_item->purge();
                $menu_item->build_all();
            }
            
            drupal_set_message('Dynamic menus have been rebuilt.');
            return '';
        }
        
        abstract class Collection {
            protected $name; //name of the collection used in paths, tables, e.g. 'womenswear'
            protected $mid; //The menu id of the top level collection menu
            protected $categoryRef; //The name of the nodereference field for the category in this collection 
            protected $designerRef; //as above, but for the designer
            private $menutree; //An array of objects, active designers within Categories for this collection
            
            public function purge() 
            //Deletes all the existing menu items for this collection
            {
                $delete_sql = 'DELETE FROM `menu` WHERE `path` LIKE "'.$this->name.'/%"';
                $delete_result = db_query($delete_sql); 
                drupal_set_message('Deleted '.db_affected_rows($delete_result).' menu items.');
            }
            
            public function build_all() {
                //Get list of all the active categories for this collection 
                //For each active category, get list of all the active designers
                
                $this->menutree = $this->getMenuTree();
                $this->insert($this->menutree);
                        
                //Clear menu cache
                db_query('TRUNCATE TABLE cache_menu');
            }
            
             private function getMenuTree() 
            //Returns an array of active Categories, with active Designers nested within
            {
                //Get list of the categories that appear under this collection,
                //duplicates removed
                
                $sql = 'SELECT node.nid, node.title, content_field_weight.field_weight_value '.
                        'FROM node, content_type_'.$this->name.'_item, content_field_weight '.
                        'WHERE content_type_'.$this->name.'_item.'.$this->categoryRef.' = node.nid '.
                        'AND node.nid = content_field_weight.nid '.
                        'GROUP BY node.title ';
                
                $result = db_query($sql);
                
                //Initialise return array
                $menuTree = array();
                $output = 'Looking at categories...';
                while ($category = db_fetch_object($result)) {
    
                    $menuTree[] = $category; 
                    
                    //Now find out which designers have products
                    //for this particular category.  Get the weight too.
                    $designer_sql = 'SELECT node.title, node.nid , content_field_weight.field_weight_value '.
                        'FROM node, content_type_'.$this->name.'_item, content_field_weight '.
                        'WHERE node.nid = content_type_'.$this->name.'_item.'.$this->designerRef.' '. 
                        'AND node.nid = content_field_weight.nid '.
                    'AND content_type_'.$this->name.'_item.'.$this->categoryRef.' = "'.$category->nid.'" '. 
                    'GROUP BY content_type_'.$this->name.'_item.'.$this->designerRef;
                
                    $designer_result = db_query($designer_sql);
                    while ($designer = db_fetch_object($designer_result)) { 
                        //Add the designers onto the just-created array as a subsection of the
                        //category item
                
                        $menuTree[count($menuTree)-1]->designers[] = $designer; 
                    }
        
                }
    
                return $menuTree;        
            }
            
            private function insert($tree)
            //Puts the array created by getMenuTree into the db 
            {
                foreach($tree as $category) {
                    $insert_cat_sql = 'INSERT INTO `menu` '.
                        '(`pid`, `type`, `path`, `weight`, `title`) '.
                        'VALUES ("'.$this->mid.'", "118", '. 
                        '"'.$this->name.'/browse/'.$category->nid.'", "'.
                        $category->field_weight_value.'", "'.
                        $category->title.'")'; 
                        
                    $result = db_query($insert_cat_sql);
                    
                    //Find out the mid of the record just inserted
                    //(There must be a better way?)
                    $mid_sql = 'SELECT mid FROM menu '.
                        'WHERE `path` LIKE "'.$this->name.'/browse/%"';
                    $result = db_query($mid_sql);
                    if ($mid_attempt = db_fetch_object($result)) { 
                        $category->mid = $mid_attempt->mid;
    
                    } else {
                        drupal_set_message('Runtime Error: could not find recently added category.');
                    } 
                    
                    //insert the menus for the designers
                    foreach ($category->designers as $designer) {
                        $insert_des_sql = 'INSERT INTO `menu` '.
                            '(`pid`, `type`, `path`, `weight`, `title`) '. 
                            'VALUES ("'.$category->mid.'", "118", '.
                            '"'.$this->name.'/browse/'.$category->nid.'/designer/'.$designer->nid.'", "'. 
                            $designer->field_weight_value.'", "'.
                            $designer->title.'")';
                        
                        $result = db_query($insert_des_sql); 
                            
                    }
                }
            
            }
        }
        
        class Homecollection extends Collection {
            function __construct() {
                $this->name = 'homecollection'; 
                $this->mid = 47;
                $this->categoryRef = 'field_item_type_nid';
                $this->designerRef = 'field_homecollection_designerli_nid';
            }
        }
        
        class Womenswear extends Collection {
            function __construct() {
                $this->name = 'womenswear';
                $this->mid = 48;
                $this->categoryRef = 'field_womenswear_item_type_nid'; 
                $this->designerRef = 'field_womenswear_designerlink_nid';
            }
        }     
        
    
    Bjornovich’s picture

    In which page do I have to copy this?
    Because I'm not that good in changing the right files and so on.

    Thanks already!

    -----------------
    ..::Bjornovich::..

    jellis’s picture

    Hi,

    I'm using son of suckerfish css/javascript menuing in a drupal site i'm working on. Previously I have used Nice menus for multi-level dropdowns but this time it was decided the lighter son of suckerfish was the best option! My issue is with the expansion of list items. The top level works without a problem but when I check the box in the menu admin to expand child elements from the top level I'm having difficulty controlling when the child element appear and it's placement in relation to it's parent.

    Any suggestions would be very gratefully received.

    Cheers,
    John.

    Anonymous’s picture

    I found the problem to be on the page level.

    When you create a page or story you need to add the menu information at that time. If you do this child menus and pages expand just fine.

    If you create the page and then use the menu module to add the page to a custom menu, child menus do not expand.

    I have tried this both ways now several times. I am able to recreate and fix the problem each time.

    lebisol’s picture

    Intersting topic... and thanks for posting this! Wish I had found it before.
    this seems the be only way wihout modules - http://drupal.org/node/194813

    Many thanks for your time and sharing!

    summit’s picture

    Subscribing, having the -not-expanding issue with taxonomy_menu when I change the taxonomy/VID/TID/TID url to a userfriendly one using custom_url_rewrite.
    If I keep the url to taxonomy/VID/TID/TID the child menus nicely expanding!

    greetings,
    Martijn

    getefix’s picture

    I ran into this problem due to a custom translation module. I had all the global menu variables set properly ([items] - title, path, type, pid | [path_index][path] = $mid) but English (secondary language) menus wouldn't expand. Found out the children were lost and all that was needed was a simple call to _menu_find_parents($_menu['items']). You can't trust parents to keep track of their children on their own.