I have a question about how menu.inc uses MENU_VISIBLE_IF_HAS_CHILDREN. I've been looking at the code and it seems like it is doing what it says: if there is a parent and MENU_VISIBLE_IF_HAS_CHILDREN is set and there are in fact children (any children, whether visible or not), then make the parent visible.

I am interested in whether there is a need for a new constant MENU_VISIBLE_IF_HAS_VISIBLE_CHILDREN or if this is really redudant and what we mean by the former is always going to be the later (in which case, there seems to be a problem with the code.)

If you cannot access a menu's children then they are not visible to you. And, if you are setting a flag concerned with their being children, if they are not accessible children, why would you want the parent to be visible at all? Or, why would you want a parent menu to appear if it is dependent on their being children, but the children are not accessible?

This issue particularly centers on the "create conent" menu item in the default Navigation block. It seems like, if your anonymous user cannot create any new content (and so the children menu are all invisible) then there is no reason for the parent to be visible. And this seems to be all we mean by the MENU_VISIBLE_IF_HAS_CHILDREN constant. Or am I missing something? Do we need a separate constant for MENU_VISIBLE_IF_HAS_VISIBLE_CHILDREN?

Comments

wicksteedc’s picture

As far as I can tell, there is not a problem in the core of the MENU_VISIBLE_IF_HAS_CHILDREN functionality. MENU_VISIBLE_IF_HAS_CHILDREN makes the menu item visible if there are visible children. If the children are not visible to the current user, then the parent item does not appear. In the code in menu.inc, the $children variable only includes accessible children, in this line:

   ($parent['type'] & MENU_VISIBLE_IF_HAS_CHILDREN && count($children) > 0);

BUT you are right there is a problem with the code. There is a bug which makes such items always visible if you edit the properties of the item, because another flag gets set by mistake. It has been reported (http://drupal.org/node/58806). See also http://drupal.org/node/47212 for various workrounds.

sainib’s picture

I think this is a bug and should be fixed...I have a situation I wanted to show all the moderator related navigation link in side menu under a group - moderation - but this heading is showing up for all authenticated users not just moderators.

New field - MENU_VISIBLE_IF_HAS_ATLEAST_ONE_VISIBLE_CHILD should be added and implemented..

Any pointers from gururs??

Airport1’s picture

I am currently in the same situation. When an authenticated user is logged in,
the "Create Content" menu item shows up, although there are NOT ANY actions nor
ANY childs available!?

This seem still to be a problem in the currently latest Drupal 6.9?