URLs defined in a hook broken I have a content type that, on the node page, displays taxonomy term fields, which in turn link to the automatically generated taxonomy term view for that term.

I would like to overwrite the output of these links, which I have attempted to do in the code below.

The problem is that the URL comes out malformed as: /our-work%3Ftid%3D4 rather than /our-work?tid=4. Note that the argument 4 is just an example.

What could be the solution here? Some thoughts:


Am I using the right hook?
urlencode() doesn't seem to work here.
Using Drupal's l() function seems to output HTML, not a processed URL.
Using Drupal's url() function doesn't seem to work either, I get the same output when I build the options array, etc.

function ep3_misc_node_view_alter(&amp;$build) {
    if ($build['#bundle'] == 'work') {
    // We cycle through this array for just integer indexes, since there are also string indices.
        for ($i = 0; isset($build['field_tags'][$i]); $i++) {
            $tid = $build['field_tags'][$i]['#options']['entity']-&gt;tid;     
            $build['field_tags'][$i]['#href'] = check_plain('our-work?tid=') . $tid;
        }
    }
}
The function that you should use is url(). If you want to output an absolute URL you should use the following code:

function ep3_misc_node_view_alter(&amp;$build) {
  if ($build['#bundle'] == 'work') {
    for ($i = 0; isset($build['field_tags'][$i]); $i++) {
      $tid = $build['field_tags'][$i]['#options']['entity']-&gt;tid;     
      $build['field_tags'][$i]['#href'] = url('our-work', array('absolute' =&gt; TRUE, 'query' =&gt; array('tid'=&gt; $tid)));
    }
  }
}


If you don't want an absolute URL, replace the call to url() with the following one:

url('our-work', array('query' =&gt; array('tid'=&gt; $tid)))


check_plain() is never used to output a URL; in fact, url() doesn't use it.