I've got View and I wanted to create 'Link path:' in Field Configuration as follow (Output this field as a link):
node/add/page/%1/[nid]
Where %1 is my argument, and [nid] is nid of current node

This link is converted to some rubish:
node/add/page/%252F223

Any solution?

Probably related topic:
#191394: Views URLs are using "+" instead of my drupal default "-"

Comments

kenorb’s picture

Temporary solution is to create tpl file:
views-view-field--my_view_name--field-image-fid.tpl.php
with code:

$output = str_replace('%5Barg1%5D', arg(1), $output); 
print $output;
merlinofchaos’s picture

I'm not 100% sure -- but is http://drupal.org/node/482162 the same problem?

kenorb’s picture

Not really, I've checked that patch, but in this place after patched line path is still correct:
node/add/parent-newsletter//224
and changed somewhere after to:
node/add/parent-newsletter/%252F224

agentrickard’s picture

@kenorb

I notice the double-slash in that URL --> node/add/parent-newsletter//224. Is that deliberate?

This looks to me like a case where the argument %1 is empty. This came up when I wrote the original patch. When the argument is empty, we don't know what to put in the URL (though I suspect it is 'all' or some other $option of the argument).

I suspect that Drupal's url() function is munging the //.

kenorb’s picture

I've tested again, and if I added 'Node: Nid' as argument and selected: 'Exclude the argument' (because then my view is hidden when passed the second argument).
Then I'm going to my view: template_picture/220
And my link now is converted from:
node/add/parent/%1/[nid]
to:
node/add/parent/Template01/223

So instead of expecting the [nid] I've got title of the node (nid = 220)

My available replacement patterns:
Fields
[nid] == Node: Nid
[field_template_image_fid] == Content: Template Image (field_template_image)
Arguments
%1 == Node: Nid

It's not working right, or I don't know how to use it properly;/

agentrickard’s picture

Well the title rewrite part is by design in the definition of the NID argument handler.

[nid] in the above replacement pattern is the NID of the returned row, which you don't want.

You probably need to make your View load the parent id as a field (set it to not display and load it before this field is used) and use that for the token. Something like:

node/add/parent/[parent_nid]

And leave the argument handler out entirely.

kenorb’s picture

Currently I've got this working by defining link:
node/add/parent/[arg1]/[nid]
using [arg1] token which is created in TPL file with following line:

$output = str_replace('%5Barg1%5D', arg(1), $output); 

It's quite complicated, but it's working.
So I understand that's not possible to get somehow arg(1) directly using Views?

In summary: Yes, this %252F probably could be because of double slash (because of missing %1).

agentrickard’s picture

The Views NID handler automatically translates NID into node title. You would need to override that in the theme layer or a custom argument handler.

See #472194: %1 output as [title] instead of [nid] in fields setting "Output this field as a link" of Views for similar and a proposed solution.

kenorb’s picture

esmerel’s picture

Status: Active » Closed (fixed)

No activity for 6 months