When you mouse over the nolink menu item in the main menu, the url shown is "example.com/" and clicking twice quickly (imitating a user thinking the first click didn't register) directs them to "example.com/" which, of course, registers as "Page not found". I also tried using "" and same result...

Dev site is located at bhs.cfaa.co and the official site will be located at bhsfinancialwellness.com when ready.

Btw, I noticed that there was a Drupal 6 issue with this. Could the problems be related?...

CommentFileSizeAuthor
#32 superfish_special_menu_items.patch1.38 KBpeterx
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

george.plescan’s picture

Version: 7.x-1.x-dev » 7.x-1.0
Priority: Normal » Major

I also notice this in the 7.x-1.0 version of the module. I install the module and I use nolink for a dropdown menu item. The result is a link to a nolink page, not found.

I have several modules installed, but i don't think there might be conflicts, except with the nice menus module.

Hope we can get any help on this as this bug is a module breaker.

PS: I tried editing the comment to show the nolink with smaller and greater, but I don't know how ?

iaminawe’s picture

I can confirm this bug

nordicmaterial’s picture

I can confirm too.
Result is "a href="thepathofthewebsite/drupal/%3Cnolink%3E" in the menu item instead of omitting the a- tag.

Subscribing.

michaelgiaimo’s picture

Confirm. Subscribe.

agerard’s picture

confirm, subscribe, hope.

erok415’s picture

Sub

fizzbin’s picture

Title: Conflict with other module make nolink creates "/<nolink>" & "Page not found" » nolink creates "/<nolink>" & "Page not found"
Status: Needs work » Active

subscribing.

IMHO there should not even have to *BE* a special module for this functionality, this should have gone straight to core a long time ago. The trouble with having hover-based expand interactions (like Superfish menus) clickable is that on an iPad or similar device, how does one "hover"? On these devices you are therefore restricted to one level of menu item, the top-level items.

erok415’s picture

I second that.

timofey’s picture

+subscribing

UPDATE: The problem is caused in combination with a SuperFish menu module. It does work in regular menus.

erok415’s picture

I'm using Nice Menu's and nesting Menu Minipanels. The result is / instead of nothing happening.
E.

timofey’s picture

ok, so I researched the problem... and it seems like an ugly one....

Basically SuperFish and other menu modules rewrites the menu structure, and some even force menu items as links, therefore any functions passed to the menu don't get counted in. :( sad. There are many posts relating to this:
http://drupal.org/node/1190688
http://drupal.org/node/1007054

Because it gets rewritten and to the fact that we're forced to have menus as links, the only solution I see on the side of Special Menu, is to attach '#' as a 'link_path' attribute.
see http://drupal.org/node/1221294

You can also manually edit superfish.module (not recommended) and change:

      $output['content'] .= l($menu_item['link']['title'], $menu_item['link']['link_path'], $link_options);

into

      if ($menu_item['link']['link_path'] == '<nolink>') {
      $output['content'] .= '<span class="nolink">' . $menu_item['link']['title'] . '</span>';
      } else {
      $output['content'] .= l($menu_item['link']['title'], $menu_item['link']['link_path'], $link_options);
      };

Reset Cache

UPDATE: to copy the <a> attributes to the new <span>, see post #25.

erok415’s picture

@timofey

Do you have any idea of how to do this with Nice Menus? I know it is a branch of Superfish but the code you have doesn't match the code in nice_menus.module. Any help would be much appreciated because I have a bunch of menu items that I need to disable.

E.

timofey’s picture

Title: Conflict with other module make nolink creates "/<nolink>" & "Page not found" » nolink creates "/<nolink>" & "Page not found"
Status: Postponed » Active

@erok415
For this, you'll need to edit nice_menus.module (in nice_menus module directory)

Option #1.
[removed] - use the second option.

Option #2, replace this :

  return l($variables['element']['#title'], $variables['element']['#href'], $variables['element']['#localized_options']);

with this:

  if ($variables['element']['#href'] == '<nolink>') {
  return '<span class="nolink">' . $variables['element']['#title'] . '</span>';
  } else {
  return l($variables['element']['#title'], $variables['element']['#href'], $variables['element']['#localized_options']);
  }

Reset Cache

Code updated per Post #16

erok415’s picture

@timofey
Will do and thanks for the help. I'll report back right away.
E.

erok415’s picture

@timofrey

First, thanks so much for helping out. It's people like you that makes using Drupal a blast.

I tried using the first option and when I enter it in, I get a syntax error (using Dreamweaver CS5.5 as my editor). I'm not to adept at writing JS so I wasn't going to try to fix it. It looks to me like the structure of your code vs. the code I'm replacing is off though. Here is a snippet of code that I'm replacing which is in two areas.

The code below comes from the module Nice Menus ver. 7.x-2.0
Starting at line 448 in nice_menus.module

 (ignore opening and closing php)
$element = array(
          '#below' => '',
          '#title' => $menu_item['link']['link_title'],
          '#href' =>  $menu_item['link']['href'],
          '#localized_options' => $menu_item['link']['localized_options'],
          '#attributes' => array(),
        );

Starting at line 471 in nice_menus.module

 (ignore opening and closing php)
$element = array(
          '#below' => '',
          '#title' => $menu_item['link']['link_title'],
          '#href' =>  $menu_item['link']['href'],
          '#localized_options' => $menu_item['link']['localized_options'],
          '#attributes' => array(),
        );

I replaced line 575 with your option 2 and unfortunately I'm still getting /. I even flushed my cache even though I'm not caching due to being in development mode. The <span> tag is not getting wrapped around the <a> tag.

Here is the code as it stands with your suggestions.

 (ignore opening and closing php)
 function theme_nice_menus_menu_item_link($variables) {
  if (empty($variables['element']['#localized_options'])) {
    $variables['element']['#localized_options'] = array();
  }
  //return l($variables['element']['#title'], $variables['element']['#href'], $variables['element']['#localized_options']);
  if ($variables['element']['#href'] == '/') {
  return '<span class="nolink">' . $variables['element']['#title'] . '</span>';
  } else {
  return l($variables['element']['#title'], $variables['element']['#href'], $variables['element']['#localized_options']);
  }
}
Morasta’s picture

@ #13,

Got it working with option #2 D7, latest everything. Go into nice_menu.module and scroll to the very bottom and comment out the line timofey mentioned. Then copy and paste his solution into the module. I made one change here: on the if line I check for what the module instructs you to enter.
if ($variables['element']['#href'] == '<nolink>') {

Had to flush my site's cache to pick up the changes, but now it's great. Many thanks for the easy solution.

timofey’s picture

@Morasta, thanks for the feedback! I corrected the code.

@erok415, try #13 again. It should work now.

You can see a working versions of the modified superfish.module here cityhill.timofey.com.
Site only tested with latter version of Chrome & FF.

gagarine’s picture

Title: nolink creates "/<nolink>" & "Page not found" » Conflict with other module make nolink creates "/<nolink>" & "Page not found"
erok415’s picture

Status: Fixed » Active

@timofey

Darn I just typed my whole response and then clicked on your example site, which by the way is way cool for a church. Then I lost all of my response.

Rather than writing it all over again with examples, I will keep it short.

Your code removes all of if any id's, styles and any other attributes that were part of the <a> tag which code determine how the navigation looks.

E.

erok415’s picture

Status: Active » Fixed

@timofey,

I did it!...and it was much easier than I thought it would be. I reviewed your syntax and the .module file again and looked at your code suggestions (#13) again. I found that if I use your final return line with a slight modification to send #href a '#', my problem was solved. So here it is and tested.

 (sans the php opening and closing php tags, for color purpose only)
function theme_nice_menus_menu_item_link($variables) {
  if (empty($variables['element']['#localized_options'])) {
    $variables['element']['#localized_options'] = array();
  }
  //return l($variables['element']['#title'], $variables['element']['#href'], $variables['element']['#localized_options']);
  if ($variables['element']['#href'] == '<nolink>') {
  return l($variables['element']['#title'], $variables['element']['#href'] = '', $variables['element']['#localized_options']);
  } else {
  return l($variables['element']['#title'], $variables['element']['#href'], $variables['element']['#localized_options']);
  }
}

Notice using the bottom return with a slight modification. When I used your original code, it returned a <span class="nolink">#title</span>. Which stripped out all of the styles, classes and id's from the tag. That didn't work and made it look horrible.

With my modification, I'm returning all of the original attributes using #localized_options, including the #title. The line $variables['element']['#href'] = '#' replaces with #. If you click this link, it will take you now to the homepage or root.

Well thank you for working with me to find a solution to Special Menu module working with Nice Menu module. Now they play nice. I hope others will find this useful.

E.

timofey’s picture

Status: Active » Fixed

@erok415

The l($title, $url, $attributes) converts the stuff into <a $attributes href="$url">$title</a>. Converting a nolink into blank URL(<a $attributes href="">$title</a>) is not html/browser compliant... it won't work in many scenarios & browsers.

try this, this will convert the <a $attributes href="$url">$title</a> into <span $attributes>$title</span>:

  if ($variables['element']['#href'] == '<nolink>') {
  return '<span class="' . implode(' ', $variables['element']['#localized_options']['attributes']['class']) . ' nolink">' . $variables['element']['#title'] . '</span>';
  } else {
  return l($variables['element']['#title'], $variables['element']['#href'], $variables['element']['#localized_options']);
  } 

I don't think there are any id attributes passed... so we're only moving classes, but it there are, you can do this:

  if ($variables['element']['#href'] == '<nolink>') {
  return '<span id="' . implode(' ', $variables['element']['#localized_options']['attributes']['id']) . '" class="' . implode(' ', $variables['element']['#localized_options']['attributes']['class']) . ' nolink">' . $variables['element']['#title'] . '</span>';
  } else {
  return l($variables['element']['#title'], $variables['element']['#href'], $variables['element']['#localized_options']);
  }
erok415’s picture

Status: Fixed » Needs work

@timofey

Although your solution may meet most goals, It seems that I'm not making my point. I need to keep the <a> included in the code so that the dropdown works.

However, I will try it, change my style sheet to include this new structure and report back.
E.

erok415’s picture

@timofey

I didn't realize that my breadcrumbs are not included in this retrofit. My breadcrumbs are still displaying /<nolink>. I'll have to work on that one to.

Any suggestions?
E.

Scipr’s picture

Title: nolink creates "/<nolink>" & "Page not found" » Conflict with other module make nolink creates "/<nolink>" & "Page not found"
Status: Active » Needs work

@timofy

The look of my superfish menu item is gone when I manually edit the code of superfish.module (#11). Is there a way to keep the look of the item?

Thanks.

timofey’s picture

@erok415
Sorry, i don't have nice-menus installed. I can't test it.

@Scipr
The old code:

      $output['content'] .= l($menu_item['link']['title'], $menu_item['link']['link_path'], $link_options);

replace with the new code:

      if ($menu_item['link']['link_path'] == '<nolink>') {
        $output['content'] .= '<span class="' . implode(' ', $link_options['attributes']['class']) . ' nolink">' . $menu_item['link']['title'] . '</span>';
      } else {
        $output['content'] .= l($menu_item['link']['title'], $menu_item['link']['link_path'], $link_options);
      };

Basically, you carry over the attributes ($link_options) from the old menu item into your new nolink menu item.

You may have to also modify css. If superfish directly styles the <a> tags, you'll need to modify the css to also include the <span> tags.

phoenix’s picture

Version: 7.x-2.x-dev » 7.x-1.0
Status: Closed (fixed) » Needs work

Having the same problem. I have the superfish module and this results in <a href="/%3Cnolink%3E"...

Bitbull’s picture

subscribing (same issue with marinelli theme and megadropdown for main menu activated - - no other module involved!)

gagarine’s picture

Status: Needs work » Postponed

I will love to see first witch direction we can't take for #1287610: Create a Menu Item Type API. Sadly other maintainers didn't answer neither users.

We can fix for XY module but is going to break every time we have a new module. I don't want that...

If we make an more generic module (like token) we can provide:
1) A way for other module to integrate

2) a option to create "fake link" with some JS in case the module doesn't provide a good integration

<a href='#'>fake link</a>

And the code than manage menu link can be all in one place.

So I put as postponed until some peoples give me some review about it (please do in #1287610: Create a Menu Item Type API).

kingfisher64’s picture

I'm using the solution (temporary patch) for superfish provided by timofey in #11.

One thing worth mentioning for the superfish temp fix, to achieve the same look as the default menu style add the following code to superfish.css in sites/all/libraries/css/superfish.css

span.nolink {
	display: block;
	position: relative;
	border-left: 1px solid #FFFFFF;
	border-top: 1px solid #CFDEFF;
	padding: 0.75em 1em;
	text-decoration: none;
}

I obviously don't like editing another module to get to this solution - even though it works great, does anybody know who far along a permanent solution is?

Edit
Referenced wrong post number.

timofey’s picture

Title: nolink creates "/<nolink>" & "Page not found" » Conflict with other module make nolink creates "/<nolink>" & "Page not found"
Status: Active » Postponed

@kingfisher64
post #13 is actually for nicemenus; superfish is posts #11 and #25 :)

sifaan’s picture

to match the look of other menus (with links) you actually have to consider the theme you are using; e.g. I am using Sky, which has rounded borders on the top, etc, so the following css worked better for me:

span.nolink {
   display: block;
   position: relative;
   border-radius: 8px 8px 0 0;
   padding: 0 2em;
   text-decoration: none;
   line-height: 2.5em;
   white-space: nowrap;
   background-color: #E1DFDC;
}

span.nolink:hover {
   background-color: #ffffff;
}
peterx’s picture

universalhandle’s picture

For Nice Menus check out this patch I just posted: http://drupal.org/node/1216372#comment-5311044. Please test and review; let's see if we can get this committed!

gabri86’s picture

I replace with this code to avoid having to modify the css

if ($menu_item['link']['link_path'] == '<nolink>') {
        $output['content'] .= '<a class="' . implode(' ', $link_options['attributes']['class']) . ' nolink">' . $menu_item['link']['title'] . '</a>';
} else {
        $output['content'] .= l($menu_item['link']['title'], $menu_item['link']['link_path'], $link_options);
};

This way we have a label <a> but not href=""

Tell me if I'm wrong.

P.S.: Sorry for my bad english, Google translate don't help me so much

cokreza’s picture

Thank you..
I add this in my template.php, and it's works!

function yourtheme_nice_menus_menu_item_link($variables) {
  if (empty($variables['element']['#localized_options'])) {
    $variables['element']['#localized_options'] = array();
  }
  if ($variables['element']['#href'] == '<nolink>') {
  return '<a class="nolink" href="#">' . $variables['element']['#title'] . '</a>';
  } else {
  return l($variables['element']['#title'], $variables['element']['#href'], $variables['element']['#localized_options']);
  }
}
sigismo’s picture

I was able to do something similar with a preprocesseor for Superfish, I guess it could be modified for nice menus as well. Here's my template.php.

//No link hack
function nroj_preprocess_block(&$variables){

$markup = $variables['content'];
$needle = '<a href="/%3Cnolink%3E" title="" class="sf-depth-1 menuparent">Distilleries</a>';
$replace = '<a title="" class="sf-depth-1 menuparent nolink ">Distilleries</a>';

$new_markup = str_replace($needle, $replace, $markup);
$variables['content'] = $new_markup;

}

ykyuen’s picture

#35 can solve the conflict between Nice menus and Special menu items module. Thanks!

gmangones’s picture

Excelent answer, thank so much, to me worked perefect..

gmangones’s picture

Hello, this answer for me is better than before. worked perfect. but i changed "#" by "javascript:". ready.

upunkt’s picture

In addition to the great #35, picking up erok415's remark in #23, that breadcrumbs still have nolink-tags.
After considering adding a "#" I realized, that linked breadcrumbs are completely unnecessary, except for the "Home"-Link. The solution is inspired by http://www.atlanticbt.com/blog/how-to-add-custom-fields-to-drupal-7-brea...
Putting the following into template.php is working for me. Drupal 7, "Basic"-Theme. This theme has already a "function YOURTHEME_breadcrumb($variables)", just put the code inside.
I bet all could be written more elegant, but I believe elegancy is something that many of the readers of these comments don't put on their personal top#1 in real life. Author included.

function YOURTHEME_breadcrumb($variables) { // change YOURTHEME
  $breadcrumb = $variables['breadcrumb'];
  // ############ get rid of nolink in breadcrumb links,
  // print_r($breadcrumb); uncomment this line for testing
  if( isset( $variables['breadcrumb']) && !empty( $variables['breadcrumb'] )) :
    // Loop: all Elements larger than 1 loose their <a>
    foreach ($breadcrumb as &$notags) {
    $i=key($breadcrumb);
    if ($i != 1) { // first key is Home-Link
      $notags = strip_tags($notags);
    }
  }
  unset($notags);
  // print_r($breadcrumb); uncomment this line for testing
  endif;  
}
erok415’s picture

Hi,
I thought I solved this problem but the dog won't bite. I want to insert a onclick="return false" into the tag of each of my nav items. Here's my code. This solves removing the from the href but it places a "/" or root link in the href. For people who like to click on navigation items, this is very frustrating as it keeps taking them back to the root of the site (homepage). This obviously needs to be fixed. My solution is in the next comment.

function theme_nice_menus_menu_item_link($variables) {
  if (empty($variables['element']['#localized_options'])) {
    $variables['element']['#localized_options'] = array();
  }
  if ($variables['element']['#href'] == '<nolink>') {
  /*Insert the onclick="return false" in this line*/ return l($variables['element']['#title'], $variables['element']['#href'] = "", $variables['element']['#localized_options']);
  } else {
  return l($variables['element']['#title'], $variables['element']['#href'], $variables['element']['#localized_options']);
  }
}

Thanks for the help.
E.

erok415’s picture

The fix below removes the from the href and places a onclick="return false" inside the <a tag. This disables navigation items from going anywhere.

I figured it out. It's weird but it seemed to help to have the localized_options onclick in both the $showme and the return a few lines down. If anyone can explain it to me that would be great. Because when I tested the code with only one or the other, it didn't work. But when I used them together, it worked but only after the first reference to the onclick in the $showme line. Go figure!

function theme_nice_menus_menu_item_link($variables) {
  if (empty($variables['element']['#localized_options'])) {
    $variables['element']['#localized_options'] = array();
  }
  $showme = l($variables['element']['#title'], $variables['element']['#href'] = '', $variables['element']['#localized_options'], $variables['element']['#localized_options']['attributes']['onclick'] = 'return false') ;
  if ($variables['element']['#href'] == '<nolink>') {
  return '<a onclick="return false"' . $showme . '>' . $variables['element']['#title'] . '</a>';
  } else {
  return l($variables['element']['#title'], $variables['element']['#href'], $variables['element']['#localized_options']);
  }
}

The code above was tested in the nice_menus.module and worked. Surely, modifying the .module code is not a good idea and you would want to create a patch. ...or you could simply place this code in your template.php file inside your theme with a tiny modification. See below...

//Remove the opening and closing php tags first
//Now replace theme_nice_menus_menu_item_link with yourThemeName_nice_menus_menu_item_link
//Good luck!
function yourThemeName_nice_menus_menu_item_link($variables) {
  if (empty($variables['element']['#localized_options'])) {
    $variables['element']['#localized_options'] = array();
  }
  if ($variables['element']['#href'] == '<front>') {
	  return l($variables['element']['#title'], $variables['element']['#href'], $variables['element']['#localized_options']);
  }
  $showme = l($variables['element']['#title'], $variables['element']['#href'] = '', $variables['element']['#localized_options'], $variables['element']['#localized_options']['attributes']['onclick'] = 'return false');
  if ($variables['element']['#href'] == '<nolink>') {
	  return '<a onclick="return false"' . $showme . '>' . $variables['element']['#title'] . '</a>';
  } else {
	  return l($variables['element']['#title'], $variables['element']['#href'], $variables['element']['#localized_options']);
  }
}

Sources that helped:
http://bit.ly/zMZ6Uo
http://bit.ly/yPcbvs
http://bit.ly/zqqc50

Question: Can anyone explain why the onlclick is required in both the $showme and the return?

Anonymous’s picture

I am using the most recent Superfish menu module for D7 in the latest version of D7 and the latest special menu items module for D7, and had an issue using on parent menu items ( I would get a page not found error when visiting the parent link) and this worked like a charm for me.

Link: http://drupal.org/node/1447988

I downloaded this file which replaces the default my special_menu_items.module file in the special menu items module folder (located in sites/all/modules/special_menu_items/) and then had to add .menuparent class to my various css files since I found that once the above file was replaced my menu link wasn't being styled properly. Now the works like a charm. I hope this helps anyone struggling with this issue as it's been a week trying to find a resolution. Thank you to mehrpadin for posting the fix.

CodigoVision’s picture

Using Superfish:
Made a small change to #36 to make it more universal and it worked great!

function yourtheme_preprocess_block(&$variables){

$markup = $variables['content'];
$needle = 'href="/%3Cnolink%3E"';
$replace = 'href="#" class="nolink"';

$new_markup = str_replace($needle, $replace, $markup);
$variables['content'] = $new_markup;

}
aubjr_drupal’s picture

After looking at the work done throughout this thread, including the latest work at #42 and #44, I installed the Special Menu Items module and was going to try making a mix of those solutions work in template.php.

However, after a couple of failed attempts, I tried something that was so simple that I thought, "That just can't work": I went into /admin/config/system/special_menu_items and set the 'HTML tag for "nolink"' to <a> (the anchor tag) - and it worked! It kept the Nice Menus structure and dropdowns, etc.

Caveat: This workaround does not work with breadcrumbs (you get <nolink> for your destination URL).

wrg20’s picture

I just used JQuery to disable the link and make it black.

jQuery(document).ready(function($) {
        //remove hyperlink
	$('#superfish-1 a[href="/%3Cnolink%3E"]').removeAttr('href').css('text-decoration', 'none').css('color', 'black');
});
Screenack’s picture

As I'm using Superfish, this affects my usage. Like wrg20, I found jQuery an effective work around: http://css-tricks.com/snippets/jquery/disable-parent-links-in-nested-lis...

gagarine’s picture

Version: 7.x-1.0 » 7.x-2.x-dev
Status: Postponed » Active

still a problem on the 2.x branch?

gagarine’s picture

Status: Active » Postponed (maintainer needs more info)
imclean’s picture

7.x-2.x-dev looks good to me, thanks.

gagarine’s picture

Status: Postponed (maintainer needs more info) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Status: Needs work » Closed (fixed)
jsimonis’s picture

Issue summary: View changes

I'm using nice menu and I'm still getting this. I've tried the dev version and I've tried the last fix listed above for nice menu.

jsimonis’s picture

If I try the jquery method mentioned above, where would I put that?