Replacement tokens do not work in link's target when you set checkbox "Output this field as a link" for a field.
I applied a patch to resolve this issue.

If this is not a bug, there should be a notice to users explaining that the replacement tokens do not apply to the Target field

CommentFileSizeAuthor
views_handler_field.inc_.patch547 bytesdan.nsk

Comments

merlinofchaos’s picture

Status: Active » Needs review

Setting proper status

Is there a use case for that kind of data in the target field?

dawehner’s picture

Sure. For example if you build a dynamic link to yourfancystuff_with_nodeid/[nid]

merlinofchaos’s picture

No, link target is where you add things like target="_blank" to the link so you can have it come up in other windows.

merlinofchaos’s picture

Unless I'm totally misremembering, that is.

dan.nsk’s picture

Here is my usecase. I need to provide the content administrator with an ability
to manage a set of advertisment links (for example). One way to achive this is to create a
simple node type and use its body's text to compose a link. WYSIWYG editor
could be used.

But sometimes this way seems to be too complex. Administrator is too lazy and
doesn't want to deal with raw HTML or even visual editor.

So I create a node type with separate cck-fields for link's URL, text, target
and title and create a view to output the list of links. I add to my "Link text"
cck-field to the view and enable checkbox "Output this field as a link".
Then I fill all the link's properties with tokens. For example, I use [field_link_url_value]
for "Link path" and [field_link_target_value] for "Target".

That's why I need tokens to apply in link's target

_vid’s picture

My use case is very similar to dan.nsk.
I have a custom content type for links with name, url, description and a target check box: 'open in a new window' {"off","on"}.
Then in my view I exclude and rewrite [field_link_target] as "_blank" and hide if blank.
Then I exclude url and body.
With the title I attempted to rewrite the output like this:
<a href="[field_link_url_value]" title="[body]"[field_link_target_value]>[title]</a> but both body and field_link_target_value were ignored while in a link. *(field_link_target_value was rewritten as ' target="_blank"' at that point.

So I used output this field as a link and put [field_link_target_value] in for the target. But since check_plain is used it actually outputs target="[field_link_target_value]".

*edit - Oh, I just noticed the patch! The following is redundant
Here is the fix that worked for me:

//changes in document: views/handers/views_handler_field.inc
    /*- line 609*/$target = check_plain(trim($alter['target']));
    /*+ added strtr(..., $tokens), to process tokens in target */	
    $target = check_plain(trim(strtr($alter['target'], $tokens)));

That works great for me. If that seems logical I hope you'll consider including this change.
In the interim I'd like to override views_handler_field.inc but adding the modified version to my theme folder didn't work. I'll have to dig around and see if there's a better way to override views functions.

Keep up the great work!

Thanks.

crashtest_’s picture

Status: Needs review » Reviewed & tested by the community

I can see that the case presented in comment 5 could be pretty useful in the right circumstances, such as his. I hadn't though to use it that way, but it does make sense.

Tested the patch, works fine. Now, we just need a "rel" field so we can add rel="lightbox" to it :)

merlinofchaos’s picture

Status: Reviewed & tested by the community » Fixed

Committed to all branches. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.