Improvement to menu href link generation logic

Bug #894291 reported by Don Schoeman
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
PHPDevShell
Fix Released
Medium
TitanKing

Bug Description

An improvement may need to be made to the mod_menu_a() function in the mods.php files under the themes files.

Lets give an example of the problem first:
Imagine you would like to create a new menu item called "Home". This menu item is not going to be placed somewhere in the menu's itself but is going to be a button somewhere on your page. So you are going to Hide it from the top menu. The "Home" menu also simply references/links to an existing menu, let's say "Dashboard". So the way you are going to configure the Home menu is:

1) Under Select Node Type: Set the menu to: (3) Jump to Link: Dashboard
2) Hide Menu: "From All" or "From Menu Only"

The problem comes in when you would like to render the a href tag for this link in your own theme. One would typically use the mod_menu_a() function in the mods.php file to do this. The problem is that mod_menu_a() thinks that this menu item is simply a place marker and therefore renders the <a href> tag as:
target="_self"
instead of rendering the real target for the menu.

The problem with this is that it is assumed that when a menu item is hidden from all, or from the menu itself, that it is a self referencing link and this may not always be the case. Of course one can simply change the mod_menu_a() function to suite your needs better but it takes a while for one to figure out what is going on and why your menu isn't working as it should. In my case for example I had to change the line:
if ($mr['menu_type'] == 6 || ($mr['hide'] != 0 && $mr['hide'] != 2))

to

if ($mr['menu_type'] == 6 || ($mr['menu_type'] != 3 && $mr['hide'] != 0 && $mr['hide'] != 2))

The question is, can mod_menu_a() be improved to handle this situation better by default or is it going to cause problems elsewhere?

Tags: menu mods
Changed in phpdevshell:
importance: Low → Medium
assignee: nobody → TitanKing (titan-phpdevshell)
status: Opinion → Confirmed
Revision history for this message
Don Schoeman (don.sch) wrote :

If this is not going to break anything else I think the mod_menu_a() function could simply be changed to this (notice I removed the checks for hidden menu's on the 4'th line:

function mod_menu_a($mr, $class='')
{
 // Check if we have a place marker.
 if ($mr['menu_type'] == 6) {
  $noclick = 'onclick="return false;"';
  // Create URL.
  $url = "&#35;";
 } else {
  $noclick = '';
  // Last check if it is a link item that should be jumped to.
  if ($mr['menu_type'] == 5) {
   $url = $mr['menu_link'];
  } else {
   $url = $mr['href'];
  }
 }
 ($mr['new_window'] == 1) ? $target = '_blank' : $target = '_self';

 /**
  * Class types:
  * nav-grand
  * nav-parent
  * child
  */
 if (empty($class))
  $span = '';
 else
  $span = "<span class=\"{$class}\"></span>
  ";

 return "<a href=\"{$url}\" target=\"{$target}\" {$noclick}>
    {$span}{$mr['menu_name']}
   </a>
   ";
}

Changed in phpdevshell:
status: Confirmed → Fix Committed
Changed in phpdevshell:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.