We currently have the % wild card, which acts as explained in the following example:

hook_menu path: search/node/%
Sample path 1: search/node/some+keywords
Here: % is equals to some keywords.
Sample path 2: search/node/some/keywords
Here: % is equals to some and not some/keywords. Obviously because % wild card is meant to provide the argument within the slashes

So in this case, the tabs on search page link to say: search/user/some instead of search/user/some/keywords.

So, the proposal is to introduce a tail wild card. Say a symbol like $. It can be only used at the end of the path, to return the whole proceeding url starting that particular wild card position. Consider the following example:

hook_menu path: search/node/$
Sample path 1: search/node/some+keywords
Here: $ is equals to some keywords.
Sample path 2: search/node/some/keywords
Here: $ is equals to some/keywords.
Which is the desired result, and the tabs link to correct paths as well like search/user/some/keywords.

This feature could be used in path module's new upcoming interface at http://drupal.org/node/147143

I know we are in code freeze, but this is a necessity(unless someone has a way for D6 to have correct tab links and correct arguments passed to the forms). Also encoded strings can be used, but won't vote for it, it won't be much readable. chx had earlier pointed that this could be hard to implement but not impossible.. It's upto the menu system developers.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Gurpartap Singh’s picture

Category: feature » bug

The tabs are broken on search pages in the case explained above. Marking as bug report.

chx’s picture

Status: Active » Needs review
FileSize
2.45 KB

I have introduced tail arguments and fixed a search warning. Note that there is another issue with search tabs, content always points to 'search' but that's a separate issue.

chx’s picture

Note: a PHP function can always take less arguments than called with so your to_arg functions needs not to be changed after this patch.

eaton’s picture

It took me a bit to figure out what the underlying issue is, but the key is paths where trailing parameters may contain slashes.

The example of search tabs is instructive.

1) You use the search box in the sidebar to search for "foo/bar"
2) That gets turned into "search/node/foo/bar
3) The search module automatically generates tabs on that page to search users, etc for the same terms
4) Because "/" appears in the search term, the menu system splits it incorrectly
5) The resulting user search points to "search/user/foo" and the "/bar" portion of the term is lost.

This patch solves it by introducing the '$' wildcard character for menu path definitions. It means, "Treat everything after this point as a single argument, regardless of slashes."

It's a specific set of steps, but other modules that need dynamic paths based on user input, or pagets that use GET arguments form a form, are likely to encounter it.

I'm not familiar enough with the system to know whether this is common enough to make the solution part of core, but I thought iving a more detailed explanation for those not already immersed in the menu system woudl help.

chx’s picture

This patch solves it by introducing the menu_tail_to_arg function. No separate wildcard.

eaton’s picture

Whoops. My mistake. Thanks for correcting, chx.

pwolanin’s picture

Status: Needs review » Needs work

this isn't quite the right fix for search module search_help call - you can take that out since there's a patch I made earlier: http://drupal.org/node/157577

I think the patch needs to be more general. For some reason, tabs go away all together on a path like node/2/xxx

pwolanin’s picture

Ahh, this is a problem specific to node/% since comment module declares a node/%/% path.

pwolanin’s picture

FileSize
2.69 KB

This patch leave the search_help fix to the other patch.

Also, a partial fix for the 'Content' tab - the reason it doesn't get the right path is that it's a default local task to /search, and our previous work makes it so that the default task tab must point to the root path. However, this fix isn't totally right either.

Gurpartap Singh’s picture

Status: Needs work » Needs review

So in a way, %menu_tail is the new wild card(or the way to fetch anything after that arg). Right?

Marking code needs review, which hopefully is done as it's being published by both chx and pwolanin :)

Gurpartap Singh’s picture

The comment changes in patch:

  * @param $to_arg_functions
- *   An array of helper function (ex: array(1 => 'node_load'))
+ *   An array of helper function (ex: array(2 => 'menu_last_to_arg'))
  */
function _menu_link_map_translate(&$map, $to_arg_functions) {

Was the "menu_last_to_arg" meant to be "menu_tail_to_arg"?

chx’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
2.69 KB

If all the problems pwolanin could found was removing feature creep then it's as good as it gets and we will fix the content tab in a separate issue.

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Needs review

Let's discuss this a bit. If the search paths are *the* use case, then IMHO we are better off with encoding the slash. We do encode other non-URL chars too (think of any accented chars).

pwolanin’s picture

here's a simpler solution - slashes are not allowed as separators...

Gurpartap Singh’s picture

Patch needs to be re-rolled.

Steven’s picture

Let's discuss this a bit. If the search paths are *the* use case, then IMHO we are better off with encoding the slash. We do encode other non-URL chars too (think of any accented chars).

Since urlencoded characters are syntactically equivalent to the unencoded character (in cases where the unencoded character has no special meaning), this would achieve nothing. This is exactly the reason why our workaround for Apache's %2F-blocking 'feature' works.

chx’s picture

FileSize
9.17 KB

So I typed in foo/bar/this that/more as a search and look where the users tab point to: foo.

chx’s picture

FileSize
9.04 KB

This is after the patch.

chx’s picture

FileSize
2.36 KB

Applied still with offset. Clearer if I reroll.

Gurpartap Singh’s picture

Title: Introduce "Tail arguments" wild card in menu paths » Introduce "Tail arguments" in menu paths
Status: Needs review » Reviewed & tested by the community

Those screenshots explain is more properly.

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Great, looks ok. Thanks, committed!

Anonymous’s picture

Status: Fixed » Closed (fixed)
basicmagic.net’s picture

subscribe

isaakordonez’s picture

suscribe