I need to have menu items that ether link to external sites, have a query string (GET variables) or named anchors. But I had problems with this because user defined menu items were being url encoded and this would break the links. So first I tried hacking the drupal_urlencode function using the parse_url function to try and make the drupal_urlencode function more flexible, but because this function is used more generally I had a problem with getting it to work under all conditions.

So I tried hacking the menu system and menu module, and I think I got it write.

before:
href="node/123%3Fvar1%3Done%2526var2%3Dtwo%2523section1"

after:
href="node/123&var1=one&var2=two#section1"

Not a 100% (&) but the links seem to work.

I searched drupal.org and found quite a few people also having problems with urls being incorrectly encoded.

http://drupal.org/node/85331
http://drupal.org/node/72812
http://drupal.org/node/59674
http://drupal.org/node/56755
http://drupal.org/node/76034

I think this is pretty important since users cant define any url they want as a menu item. And it is something I personally often require. I am not sure if this is a bug or feature request, but since the links were broken I thought it would be considered a bug.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chx’s picture

Title: complex menu items = broken urls » Menu should support query and fragment in links
Category: bug » feature
Priority: Critical » Normal
jacauc’s picture

How do I apply this patch to my currently running setup?
It doesn't seem to work in the same way as when I normally apply patches.

Thanks
jacauc

NaX’s picture

This patch is for drupal CVS not for 4.7

I tested it using patch -p0 < menu_paths_nax.patch and it worked. How do you apply patches.

NaX’s picture

Version: x.y.z » 6.x-dev
Priority: Normal » Critical
Status: Needs review » Needs work
moonray’s picture

Brilliant. I was just about to post an issue about this.

I was going to work on a patch as well, but then I saw that chx is working on a complete menu overhaul, so can't do anything until that's done.

One comment, though: I found the linking system to be inconsistent. Menu links have one syntax, links from hook_link() and hook_alter_link() another, and breadcrumbs yet again are different. It would be great if we could use the same syntax for all three (the syntax for hook_link() seems the best).

Steven’s picture

Note that the following patch does a lot to simplify links, and introduces a structure that should be reused by other modules: http://drupal.org/node/111347#comment-191811

Waiting for a reroll for HEAD...

bdragon’s picture

FileSize
1.62 KB

My strings REALLY SUCK. But, this feature is very easy to implement in the new system!

bdragon’s picture

FileSize
1.62 KB

My strings REALLY SUCK. But, this feature is very easy to implement in the new system!

bdragon’s picture

Possibly put these in a collapsed fieldset ("Advanced?")?

chx’s picture

Title: Menu should support query and fragment in links » Menu does support query and fragment in links
Category: feature » bug
Priority: Critical » Normal
FileSize
5.36 KB

I asked grugnog whether fragment or anchor and he basically said why separate fields. Right.

chx’s picture

I asked grugnog whether fragment or anchor and he basically said why separate fields. Right.

Owen Barton’s picture

Status: Needs work » Reviewed & tested by the community

Tested and menus save and edit, validation still works on invalid paths and the query/anchor is added back in correctly on edit/view. Looks good.

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Needs review

Hm, how does the UI look like (screenshot) for this? I wonder how people provide query strings and anchors, which need to be derived differently from the actual site URLs on different sites. I see it is easy to split and to join strings here, but what is the user experience?

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

Looks to me like there is no UI impact at all. We just use any querystring and fragment that is provided in the path field. i think thats reasonable, and even expected.

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

OK, committed.

Anonymous’s picture

Status: Fixed » Closed (fixed)
telcontar’s picture

Any chance backporting this to 5.x?

telcontar’s picture

Status: Closed (fixed) » Active

I've tested this on HEAD. Menu paths of the form 'path/to/node#fragment' work. But one might like to add a link to a local anchor on the current page, e.g. use '#fragment' as a menu path. This does not work on HEAD.

A practical example where this would be useful is "Skip Navigation" links for accessibility.

-- telcontar

catch’s picture

Status: Active » Needs work

seems reasonable and arguably a bug with the original patch, so setting back to CNW.

xamount’s picture

I second the backport to 5.x

chx’s picture

Title: Menu does support query and fragment in links » Support fragment only links
Version: 6.x-dev » 7.x-dev
Category: bug » feature
Status: Needs work » Active
sonicthoughts’s picture

please backport to 5.6/5.7. this has been very frustrating!
tx

kimothy777’s picture

I'm glad I'm not the only confused party here.

http://www.mychildcanbehave.com

pwolanin’s picture

Status: Active » Closed (works as designed)

I'm dubious about the anchor-only links - making those work is going to be very theme dependent. You could also add such a "skip" link to your template, or use hook_translated_menu_link_alter.

tobias’s picture

+1 on backporting to a drupal 5.x version - would this still be possible or has it been done?

cheers,

tobias