1

I have an image field in Views, for which I must use "Rewrite output" option. The output of the image field is this:

<a href="/taxonomy/term/[tid]" title="Album &quot;[name]&quot;" class="vignette-wrapper">
[field_image]<span class="vignette"></span></a>

So, it contains a link to taxonomy term. But I would like this link to be the custom url for this taxonomy term, instead of raw Drupal path. My Pathauto pattern for taxonomy term is:

[term:vocabulary]/[term:parents:join-path]/[term:name]

But in Views, the [term:parents:join-path] token is not visible on the list of Replacement Patterns.

How to achieve this?

5
  • I'm curious, does the /taxonomy/term/[tid] URL not automatically redirect to your pathauto determined alias? I know that's not ideal compared to serving the pathauto version.
    – cdmo
    Commented Mar 8, 2013 at 16:09
  • Nope. Should it? When I type raw Drupal path in the browser directly, it also stays this way. I think custom path works when using php functions like l() or url(), but maybe I am missing some settings
    – camcam
    Commented Mar 8, 2013 at 16:24
  • Ah, I've got drupal.org/project/globalredirect enabled, which does do this. So, there's one, less good potential solution. You could also look into hook_views_pre_render() to strongarm it. Not sure exactly what that would look like, but maybe something along the lines of changing $view->field['FIELDNAME']->options['alter']['path']
    – cdmo
    Commented Mar 8, 2013 at 16:33
  • The global redirect module solves this problem (and some others, too). So I would like to accept it as answer, could you please create an answer? I didn't succeed using hook_views_pre_render(), but discovered along the way that a field template override (as in Advanced->Theme section of view definition) gives access to those field values, so it's another possibility to keep in mind. But theming fields may affect performance and requires extra code. I'll actually use the global redirect module.
    – camcam
    Commented Mar 9, 2013 at 8:33
  • Cool, glad that will work for you. Theming the field is another possible solution too, though some might argue that you shouldn't put content changes in a tpl. As for performance, I can't really speak on that, but Drupal's pretty good at caching...
    – cdmo
    Commented Mar 9, 2013 at 12:28

2 Answers 2

1

The Global Redirects module (drupal.org/project/globalredirect) would be one potential solution! It will automatically redirect all links on your site that are like that globally.

0

I put

function [theme-name]_preprocess_views_view_field__[view-name]__tid(&$vars) {
  $vars['output'] = drupal_get_path_alias('taxonomy/term/' . $vars['output']);
}

in template.php after adding the 'TID' field to the View. This also needs a copy of views-view-field.tpl.php, renamed according to the Theme Information provided by the View, in the theme folder in order to invoke the pre-process hook.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.