Unable to put query string in my path

Julien PHAM - October 23, 2008 - 12:21
Project:Taxonomy Redirect
Version:6.x-1.3
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

Hi,

I have an issue with the path, for instance I have created a view that takes arguments.
For instance, a link should be like this :
http://www.mindenice.fr:88/entreprises?activite=associations

But in taxonomy redirect if I put as a path value entreprises :
entreprises?activite=associations

Then when I go to the taxonomy link, it redirects me to :
http://www.mindenice.fr:88/entreprises%3Factivite%3Dassociations

And of course it does not work.

Any way to fix this? Thanks

#1

Justin W Freeman - October 30, 2008 - 06:19

You should be able to do things like this by using url encoding instead of the non-alpha-numeric characters, for example entreprises%3Factivite%3Dassociations would be your redirect if you wanted to redirect to entreprises?activite=associations.

An easy way to do this if you don't know the codes for these characters is to use php code for the path and put the following for the path:

<?php
  $url
= urlencode('entreprises?activite=associations');
  return
$url;
?>

This should work, but I have tried doing this many different ways and it doesn't work.

For some reason when you encode these characters they don't get decoded when you click the link but double encoded, so you end up with entreprises%253Factivite%253Dassociations.

Does anyone know why this is the case and/or how to get around it?

If I figure it out i'll get back to you.

#2

Julien PHAM - October 30, 2008 - 06:27

Thanks. For now I have dropped the idea of using taxonomy redirect and I have themed my view to create a customized link instead.

#3

Serebron - November 1, 2008 - 15:51
Version:6.x-1.2» 6.x-1.3

But if I wanted to redirect to vacancys&otr=!tid?

#4

Vote_Sizing_Steve - November 28, 2008 - 17:41

I'm having the same problem, and trying to *decode* the resulting url. Linking to:

http://votesizing.org/en/Content_Wizard%3Ftid%3DSteve%20Glickman

... breaks, whereas:

http://votesizing.org/en/Content_Wizard?tid=Steve%20Glickman

... does not break. I've tried a lot of things with the code, php and settings; and am starting to wonder if this module is sending the right href string, but another one is mangling/encoding/breaking it.

Thanks in advance for any help.

#5

Vote_Sizing_Steve - November 28, 2008 - 21:13

Found this post:

http://drupal.org/node/158687#comment-580458

... and fixed.

#6

ipto - March 21, 2009 - 10:02

I have views with exposed filter = b/search, in this module path for vocabulary = b/search?tid=!tid, but in result path = b/search%3Ftid%3D45
:(

#7

highvoltage - March 21, 2009 - 10:58

So this is a problem with drupal, not the module? PHP solution in #1 did not work for me.

#8

divinevette - March 21, 2009 - 16:33

Try typing the full url rather than the relative one:

http://www.example.com/b/search?tid=!tid

I've had this issue all over drupal.

Let me know if it works for you.

#9

Justin W Freeman - March 22, 2009 - 22:16

Yes, this seems to be a problem with drupal.

The solution in #5 worked for me but from reading on the issue raised in that post and a few others it linked to there are a few different issues that are looking at the problem.

Will have to have a look and see what the best of those core solutions are.

#10

highvoltage - March 23, 2009 - 13:14

unfortunately no, divinevette. It results in a repeat of the domain, because it appends rather than replaces, so you end up with:

example.com/example.com/b/search?tid=!tid.

Is it reasonable to allow for replacement instead of just appending, agileware? Or would that work at all...? Because although it reapeated the domain, everything else came out properly.

#11

mariagwyn - April 6, 2009 - 23:40

Any movement on this? I didn't understand the link in #5, or how to solve (a patrch for 5.x? on 6.x?)

I am trying to redirect my image tax links to a views filter which looks something like this: 'image-galleries/?race=55' which in tax_redirect is this: 'image-galleries/?race-!tid.' The odd thing is that if I hover over the link in firefox, it looks perfect. If I click the link, I get "image-galleries/%3Frace%3D55." In Safari, it is bad both hovered and clicked.

#12

jarchowk - April 16, 2009 - 13:13

Using the full URL worked for me, but I had to comment out the '//' replace

Line: 556
//while (strpos($path, '//') !== FALSE) {
//$path = str_replace('//', '/', $path);
//}

#13

highvoltage - April 16, 2009 - 23:26

#12 worked for me. Thanks ^_^

#14

dman - April 28, 2009 - 05:19

I traced it through and found a weakness in taxonomy_link.
If it is passed a (perfectly legal) path containing a query or fragment, it then places it into a link arrray is such a way that it would be munged when l() tries to use it later.
This can be avoided like so:

taxonomy.module.

BEWARE:core hack
SMILE: core hack -> core patch

<?php
function taxonomy_link($type, $node = NULL) {
  if (
$type == 'taxonomy terms' && $node != NULL) {
   
$links = array();
   
// If previewing, the terms must be converted to objects first.
   
if (isset($node->build_mode) && $node->build_mode == NODE_BUILD_PREVIEW) {
     
$node->taxonomy = taxonomy_preview_terms($node);
    }
    if (!empty(
$node->taxonomy)) {
      foreach (
$node->taxonomy as $term) {
       
// During preview the free tagging terms are in an array unlike the
        // other terms which are objects. So we have to check if a $term
        // is an object or not.
       
if (is_object($term)) {
########################################
          // dman 2009-04
          // Although we (specifically taxonomy_redirect)
          // can return things via hook_term_path ... Using this array
          // method of creating links encodes our URLs later!
          // I wanted to rewrite to redirect terms to a filtered view: /publications?tid=n

         
$path = taxonomy_term_path($term);
         
$url_parts = parse_url($path);
         
// Need to pass the path  back in bits to avoid encoding.
         
         
$links['taxonomy_term_'. $term->tid] = array(
           
'title' => $term->name,
           
'href' => $url_parts['path'],
           
'query' => isset($url_parts['query']) ? $url_parts['query'] : '',
           
'fragment' => isset($url_parts['fragment']) ? $url_parts['fragment'] : '',
           
'attributes' => array('rel' => 'tag', 'title' => strip_tags($term->description))
          );
##########################################

       
}
       
// Previewing free tagging terms; we don't link them because the
        // term-page might not exist yet.
       
else {
          foreach (
$term as $free_typed) {
           
$typed_terms = drupal_explode_tags($free_typed);
            foreach (
$typed_terms as $typed_term) {
             
$links['taxonomy_preview_term_'. $typed_term] = array(
               
'title' => $typed_term,
              );
            }
          }
        }
      }
    }

   
// We call this hook again because some modules and themes
    // call taxonomy_link('taxonomy terms') directly.
   
drupal_alter('link', $links, $node);

    return
$links;
  }
}
?>

I believe this code is more robust that the previous version, and is not a special-case hack (although it is an edge case).
Previously was:

<?php
          $links
['taxonomy_term_'. $term->tid] = array(
           
'title' => $term->name,
           
'href' => taxonomy_term_path($term),
           
'attributes' => array('rel' => 'tag', 'title' => strip_tags($term->description))
          );
?>

Anyway, Now I can use taxonomy_redirect to send to my filtered, exposed view like we were supposed to.

#15

mariagwyn - May 15, 2009 - 23:35

@dman: I tried this, to no avail.
#12 however, did work. I would prefer to use relative URLs, but this will work for now.

Maria

#16

mariagwyn - May 18, 2009 - 18:12

It appears that it only works, sort of.

My redirect looks like this: http://site.org/topics/!parent_names/?tid=!tid

For second level terms, this works just fine. It goes right to the correct View, with the exposed filter correctly selected.

However, first level terms look like this: http://stnina.org/topics//?tid=28

The TID is correct, but I want the URL to read: http://stnina.org/topics/term_name, no TID. In other words, !parent_term does not work.

I can of course, create redirects for all subterms, but since you can only select one subterm at a time (posting issue on this: http://drupal.org/node/466162).

#17

houen - June 5, 2009 - 16:50

Are you sure it's a problem with the core? If you examine the URL output by taxonomy redirect, it will transfor this:

strategy-guides?level=!tid&race=All&type=All

into this:

strategy-guides?level=!tid%26race=All%26type=All

which means there is a "25" too much in the URLencode

Anyway - i found a VERY weird fix - place http:// in fron of the path, like this:

http://strategy-guides?level=!tid&race=All&type=All

...And I get a nicely formatted URL - weird...

#18

dboulet - July 30, 2009 - 23:53
Category:bug report» feature request

Thanks houen, your fix works, although it should only be considered a temporary solution.

I think that the correct way to fix this issue would be to have a separate textbox in the ui where we can enter pairs of keys/values which would be formed into a query string and appended to the path. For example:

key1|!tid
key|value

would append '?key1=123&key=value'.

Ideally, we would also be able to use php here, returning an keyed array of values.

#19

sm - August 3, 2009 - 01:00

I'm finding that the proposed fix from #17 seems to have problems in the safari browsers though it seems to work in most others.

#20

dboulet - August 4, 2009 - 17:46

Looks like my proposed solution in #18 won't work because of a limitation of the way hook_term_path() is implemented in core, it only allows you to return a path as a string, and not as an array with options.

#21

sm - August 4, 2009 - 18:34

we ended up scrapping the mod and implementing in our template.php in the _links($links, $attributes = array('class' => 'links')) function. A little messy but we achieved what we needed with an array merge of query parameters with the $link and then creating the l();

#22

dboulet - August 4, 2009 - 18:37
Title:Unable to put arguments in my path» Unable to put query string in my path

#23

dboulet - August 4, 2009 - 22:32

I've had some success adding the query string using the Url alter module.

#24

Justin W Freeman - November 14, 2009 - 08:06

dman's solution in #12 makes sense and fixes it for me

I will submit a patch for drupal for that and it may or may not get in.
If not a solution similar to the suggestion in #18 might be the way to go

#25

Justin W Freeman - November 14, 2009 - 11:29

I have created an issue with dman's fix in #14 at #632646: taxonomy_link doesn't work properly if taxonomy_term_path path contains query or fragment

Hopefully it gets committed, otherwise we go a different way.

 
 

Drupal is a registered trademark of Dries Buytaert.