It seems like token in URL paths are not changed, cause I got this error: "Not a valid URL." while using token like [current-user:uid].
When I'm using the actual number everything works properly.
It works fine in title field also.

CommentFileSizeAuthor
#10 link-1047444.patch11.21 KBsweetchuck

Comments

jcfiala’s picture

Some tokens will now work with that, but others, such as tokens which provide an entire url, won't. I'm not sure what to do with this yet. I don't think there were any similar tokens that returned an entire url before.

krembo’s picture

Thanks. I'll check the update.

jcfiala’s picture

Status: Active » Fixed

Well, it's been a month and I haven't heard back, so I'm going to nudge this to fixed. krembo, if this is still a problem, feel free to re-open this ticket.

Status: Fixed » Closed (fixed)

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

Barfly’s picture

Version: 7.x-1.0-alpha2 » 7.x-1.x-dev

It's not fixed ,
when i use the token [current-page:url] in the field url the function "link_validate_url" return false.

link_validate_url should be desactivate(or work differently) when token is available.

In order to use token directly in url field i comment those lines:

 // Validate the link.
 // if (link_validate_url(trim($item['url'])) == FALSE) {
 // form_set_error($field['field_name'] .']['. $delta .'][url', t('Not a valid URL.'));
 // }

it's pretty crappy but it works ^^

Barfly’s picture

Status: Closed (fixed) » Active

active

jcfiala’s picture

Status: Active » Postponed (maintainer needs more info)

Currently, we're only doing node tokens on link fields - I don't have any idea where the [current-page:url] token is coming from - I can't find it searching the code base, so I don't even know how to include it. But that's where the problem is.

Can you tell me which module you installed that provides the current-page:url token?

jcfiala’s picture

After further looking, I found that [current-page:url] token is provided by the Token module. Fair enough.

But how are you using this token, that couldn't be handled by node/[node:nid]?

Barfly’s picture

In fact i use [current-page:url] because i want A="sub-sub-sub-node" link to B="sub-sub-sub-sub-node" ^^
the links are on "A nodes" and "B nodes" have almost the same alias as A.

with [current-page:url] , i just have to write this URL : "[current-page:url]-aliasForAll-B"

sweetchuck’s picture

Title: Token in URL paths not working » Token replacament run after the validation and only support the node entity type
StatusFileSize
new11.21 KB

Token replacement are in _link_sanitize(). It is only called from link_field_prepare_view().
The link_field_validate() does not replace tokens before validate the URL.

The other problem is the entity object always introduced as node to the token_replace().

Maybe the token_replace cannot be used if the $entity_info['token type'] is not filled.

robbiePie’s picture

Could someone please provide this patch update as a usable module? I am trying to link to the content authors profile2 page. Using the token module I can enter [node:author:my-profile:url] into the Static Title field and it resolves to the url perfectly, but in the 'Default URL' the system returns "Not a valid URL".

This seems like a pretty big issue.

robbiePie’s picture

Sweetchuck,
Thanks for providing the patch. I ran " patch < link-1047444.patch " in the same directory as the link-alpha release and it gave me two reject chunks. I took a look at the .rej file and added what didnt make it into the link.module file. After this I get no php notices at the top, but I still get the "Not a valid Url" message after adding a token to link to the content specific profile page for the author.

Any pointers where to start? Thanks!

sweetchuck’s picture

@robbiePie Patch is applicable on the latest version in the repository.
So you need a copy of the repo: git clone --branch 7.x-1.x http://git.drupal.org/project/link.git
and git apply -v [patchname.patch]

More information: http://drupal.org/project/link/git-instructions

robbiePie’s picture

Thanks! Works great now!

tuwebo’s picture

Thaks Sweetchuck!
It also works great for me!

kolier’s picture

@Sweetchuck
If site is using some module like http://drupal.org/project/field_collection together, your patch will conflict.
Will cause different result on different entity_type.

dqd’s picture

Title: Token replacament run after the validation and only support the node entity type » Token replacement runs after validation and supports node entity only
Assigned: krembo » Unassigned
Status: Postponed (maintainer needs more info) » Closed (duplicate)
Issue tags: +field validation

Dear followers of this issue: But please read the project page info of link module for further validation issues. There is already an issue to collect and discuss all possible validation scenarios in general. That's why I will mark this one here as duplicate. I need all concentration inside the ONE and only discussion to move forward. After a D7 implementation we will provide a D6 backport.

Explanation: There are too many corner cases and validation wishes of users to implement them all serially one after the other. We would have a 40 lines cluttered settings form for validation methods only conflicting each other. I think, the right way is to find a maybe more complex but all embracing configuration method, which lets the admin better decide how and when to validate the url. Including a good description which helps to set it up.

m4olivei’s picture

Title: Token replacement runs after validation and supports node entity only » Token replacement supports node entity only
Status: Closed (duplicate) » Active

That's fine that the bit about the replacement as it relates to the validation is pushed off into another ticket. However, that other ticket does not cover the issue where the token replacement supports the node entity only.

In my case, the issue occurs when you add a link field to a profile2 entity, and then use the tokens provided by entity_token.module in the Static title option. Because link.module hardcodes its the data available as node data, they don't get replaced.

I would imagine this would be an issue when link fields are used in this manner on other entities as well: user, taxonomy_term, etc.

jcfiala’s picture

Status: Active » Postponed (maintainer needs more info)

In my case, the issue occurs when you add a link field to a profile2 entity, and then use the tokens provided by entity_token.module in the Static title option. Because link.module hardcodes its the data available as node data, they don't get replaced.

Can you give more data as what's going on and what's wrong? Or even better, a patch that fixes it? I'm not sure what you mean by 'hardcodes its the data available as node data' - can you explain more?

m4olivei’s picture

Sure, let me explain a simplified case without profile2.module. Here are the steps to reproduce the issue:

On a stock D7 with token and link module installed and enabled:
-Add a link field to the user entity (Configuration > Account Settings > Manage Fields)
-On the settings for the link field, choose Static Title for the Link Title.
-In the Static title textfield, enter [user:name]'s website (this is one of the reported tokens available).
-Save
-Edit a user account on your site. Enter a URL for the link field.
-Save
-View the account. Note that it is rendered as "[user:name]'s website". The token is not expanded.

After stepping through the code, the reason seems to be that on line 494 of link.module (7.x-1.0), the $data parameter that you pass to token_replace() keys the data as a 'node' entity regardless of whether it is in fact a node or not. When token module goes to replace the tokens, it looks for $data['user'], can't find it and thus can't do the replacement. Thus this piece of code is entity-unaware and only tailors to nodes.

I believe the patch in #10 attempts to solve this issue, but is mixed in with the validation related fixes. I don't have time to patch it now. I'd start at #10 though.

mgriebe’s picture

What's the status here?

jcfiala’s picture

Status: Postponed (maintainer needs more info) » Active

Okay, that's an _awesome_ explanation in #20. Thank you.

jcfiala’s picture

Status: Active » Fixed

Alright, I've picked out bits from the patch in #10, and it seems to work. I've committed this to 7.x-1.x, and it should be available in 7.x-1.x-dev shortly.

Status: Fixed » Closed (fixed)
Issue tags: -field validation

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