We have modified the Drupal core to allow menu links to allow menu items to be opened either in the current window, or in a new window. The attached patch will modify the menu.module and menu.inc to add the functionality to the configuration menus and in the database. If your theme displays menu links, you will need to modify that as well. This is what we did for phptemplate engine:

function phptemplate_menu_item_link($item, $link_item) {
  /* Wrapper span */
  // Add menu_target if present -- JBN linuxbox.com
  if (array_key_exists('description', $item)){
    $attribs = array('title' => $items['description'], 'target' => $link_item['target'])
  } else {
    $attribs = array();
  }
  return l('<span class="lw1">'. check_plain($item['title']) .'</span>', $link_item['path'], $attribs, NULL, NULL, FALSE, TRUE);
}

-- The Linux Box [www.linuxbox.com]

CommentFileSizeAuthor
menu.patch_1.txt10.73 KBAnonymous (not verified)

Comments

Steven’s picture

Status: Needs review » Closed (won't fix)

target="..." is not valid as per XHTML, and annoys the user by taking away choice. Marking as won'tfix.

Plus, patch does not conform to code style at all and is generally messy.

GripMediaDotNet’s picture

You know this is a valid request, and I have seen several rude responses to this request. Instead of calling the code "messy", why don't you offer a solution instead of being rude?

I need an answer to this problem, and all I see is smart alec.

wsuucmedia’s picture

Title: Target window for menu links » Knock it off with the "HTML Compliance" snobbery

I second what Grip said. Sometimes the best work-around is to open in a new window (this would very quickly solve the problems I'm having with the current release standing of the Gallery embed module if I could just get Gallery to open in a new window without trying to get the two themes to play together nicely). We're not all designing for target audiences of tech gurus. Some of us are designing interfaces for little old ladies who only learned that clicking the wrong thing with the mouse will not, in fact, cause the computer to litterally explode thanks to their friendly neighborhood senior center. Opening in a new window for them to allow the interface experience to be more straight-forward and user-friendly is a valid feature request. You "it annoys the users" "it must be perfectly compliant with HTML 1.0" snobs need to get over yourselves and realize that not everyone is designing for users who have even HEARD of anything beyond "click on the little picture that looks like an E then click on the white line next to where it says "address" and type www.your-church-here.org, hit enter and then click on any words that are underlined and look interesting" - that is really the user level that many of us are designing for, and that niche deserves as much consideration as the ones that configure their browsers not to allow the opening in new window behavior anyway. Considering the average age of members of my church is about 60 years old and I'm working on this around a very active 2yo and a growing pregnant belly, I really don't have time to be YOUR mama to. Provide real help, stop being a smartass tech snob, or go stand in the damn corner and take a time-out.

djnz’s picture

I think there is a compromise here. At the moment the patch will ALWAYS add a 'target' attrribute to the link, with the value either target="_self" or target="_blank". The patch could easily be modified to only add target="_blank" when appropriate. It will then only violate XHTML 1.0 Strict when the user really wants it to.

But most Drupal themes (including the default Drupal 5 Garland theme) are XHTML 1.0 Transitional, and target is a valid attribute in XHTML 1.0 Transitional. The statement 'target="..." is not valid as per XHTML' is just plain wrong. People who make such statements might like to look at the (draft) specification for XHTML 2.0 for link attributes.

sepeck’s picture

Title: Knock it off with the "HTML Compliance" snobbery » Target window for menu links

Thank you all for your considerate responses. Some additional information.

Please review the principals

Standards-based. Drupal supports established and emerging standards. Specific target standards include XHTML and CSS.

If the modifications is not compliant per specification, then we will generally be inclined to avoid it. You can build a function in the theme template.php to override built in target criteria. Changes of the development communities direction to draft xhtml 2.0 standards would require discussion on the development list with attendant research, justification and buy in from the active core contributors and commiters and would also not be applicable to 4.7 or 5.0 series.

Project Coding standards are linked at the top level of the Handbooks page. This is a request for a change of behavior in 4.7.x series. The 4.7.x series is feature frozen as is 5.0. No new features will be added per the long existing policy.

Please do not modify title descriptions to become an attack. The given answer was brief but not rude nor an attack. The responses we're less then kind. In fact they were rants. Reasoned discussion is welcome, rants and attacks are not.

wsuucmedia’s picture

djnz - yes that's exactly what I need, I only need ONE menu item to open in a new window, not all of them (that would be completely obnoxious!). I didn't apply the patch since the programing class I took 10+ years ago somehow didn't stick ;) and I can't even quite figure out CSS coding around everything else jumping into my lap (literally), much less figure out what line to edit how so that I can get a template to do this behavior. Some of us actually need modules and other assistance for things like this and have little interest in learning how to do the intricate details ourselves, especially when we're doing the work for free for a non-profit and have other things we could be productively doing with the time, such as laundry. Really, not everyone reading these messages are tech gurus - else there wouldn't be some of the "bug reports" that I've seen (a few of which I've seen look like "RTFM" might be the least rude response possible). I'm trying to keep in mind that the folks that are helping us non-coders here are ALSO having to wade through those messages too, but it does still get annoying when it gets taken out on a project they don't WANT to do instead of on ones that really are requests for help that has already been provided if the person would just take the time to LOOK. After making one "oopsie" with my first post (replied that I was having the same problem as an issue that was labeled "closed" a month or so ago and related to a prior version, tho since the response was "upgrade to a newer version, it's been fixed" and clearly it *hadn't* I still say it was valid but I started a new bug report anyway), I've been diligently searching at least a couple months back on the other issues I've encountered before posting anything about it, in case someone's already posted a work-around or explained how to fix it. I've seen this feature requested on an almost weekly basis going back in the archives, and the same "won't fix" response made in the same rude way that seems to assume that anyone who would ask to do such a thing MUST be wanting to put an X10 ad in or something.

And my message may have appeared to you as a rant/attack, but how do you think seeing the same blow-off to so many others appears to someone who is TRYING to not ask the same question as everyone else, how do you think THAT looks? Standards are all well and good, but when they're used as something to hide behind instead of giving a real rational explaination of WHY it's so bloody necessary to stick to them in every single instance of the software's use and what does it look like? Users like me couldn't care less if it comes in the form of a change/tweak to the core code or as a module. If someone would be kind enough to throw together a module that enables this menu behavior WITHOUT completely breaking the rest of the core's functunality, I will personally mail them the food indulgence of their choice (and I make some killer cookies). Question is, with attitudes like have been expressed every time the request is made, will drupal.org actually allow such a module to be hosted here where people could find it? For all I know, it already exists, has existed for months, but isn't available here because it "violates this bunch of words we've decided to put here as a barrier to useability" (which is really how I read that statement - I've spent enough time around beurocrats to know a legalese excuse when I see one, I lived near Washington DC for 5 years, they're a daily occurance anywhere within a 50 mile radius like some kind of nuclear fallout).

If you can fix the problem, fix it however you can without violating your personal ethics and principals as a programmer or whatever, or post a link to where someone else has already done it well. If you can't, don't blow off someone making a valid request for help just because you don't like the way others have implimented similar web behaviors in the past.

sepeck’s picture

I shall try again.

This is the Drupal project. The Drupal project has a stated mission and principles that the project core code strives to adhere to. This is part of the foundation of this project. Adhering to those principals has been very important and has contributed to the success of the project. Core will continue to strictly adhere to these principals.

His stated reason was that the request did not meet valid XHTML specifications (yes he included some additional opinion bits but as someone developing to standardization for many years that's fine too). The proper setting in project module is in fact 'won't fix'. This indicates that this will not not be fixed. This is not a slam, or attack in any way. It is an indication that this issue will not be applied to Drupal core code. As one of the 3 people with core code commit rights, this is his right and responsibility to the community. The reason he gave was also valid. Not mentioned is that once a given Drupal version is feature frozen it is feature frozen as well. This is not an arbitrary rule, it is to give developers predictable behavior to develop against.

His comment was not in fact a 'blow off' at all. It was him doing the job he wasn't paid for.

So, to determine a rant... phrases such as...

  • You "it annoys the users" "it must be perfectly compliant with HTML 1.0" snobs
  • I really don't have time to be YOUR mama to
  • stop being a smartass tech snob, or go stand in the damn corner and take a time-out.

carry all the hallmarks of a rant. They are personal attacks. They use swear words (something I find interesting juxtaposed with the commentary about church sites) and name calling towards people that have spent a tremendous amount of their time contributing unpaid work to this system you are using. It is mean, petty and uncalled for. Won't fix isn't rude, it's the closing term for an issue.

This does not mean that someone cannot contribute a contributed module that allows for this behavior. It means that such behavior is not acceptable for going into Drupal core. There is in fact a contributed module called link Unfortunately it also requires being used with cck module and this is not quite straight forward but something for you to look at as a possible way to achieve your goals.

This comment outlines the theory I mentioned using a theme template.php file but is for aggregator not in node links.

Some forum posts over possible approaches (random forum search) do exist intermixed in the forums as well. Also, you can take the above code in the code tags and modify it for use in your theme as a template.php. It should work.

If you are frustrated that is understandable, but please do not take your frustrations out on the developers. You may not be getting paid for your project, but you are also not paying them on this project either. I do not say this to trivialize your frustrations but to try and help you get help more effectively.

I urge you to try a different approach. Trying a polite forum post, outlining clearly your goal and needs and what you have tried so far. You certainly have a better chance of attracting people interested in helping then your current posts in this thread.