I am not sure if this is a bug report or a feature request.

CCK link can take tokens for titles.

Can it also take tokens for urls?

It would be very beneficial if I want to create default urls for users.

Chris

CommentFileSizeAuthor
#36 412404-link.module-tokenindomain.patch1.08 KBneilnz
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

presleyd’s picture

Hmmm I was just wondering about this myself, I was sure an older version used to do this.

SocialNicheGuru’s picture

Priority: Normal » Critical
jcfiala’s picture

Category: bug » task
Priority: Critical » Normal
Status: Active » Postponed (maintainer needs more info)

Well, at the moment it sounds like new functionality. At the moment I'm concentrating on getting 6.x-2.6 out the door (see the shiny beta release? Please test!) but I'm welcome to hearing more about what you're interested in this doing. I haven't used the token functionality that is in link yet, so I'm not sure how that works in titles yet.

szegedi’s picture

Hello, I try to solve a similar problem, but that would be the best way, if token can be added to url, because I try to find way to add variables (ex: node id) to link url dinamically, but the only way is php code... a module, or a patch to link module would be better...
Thnx
Szg

SocialNicheGuru’s picture

From what I read, tokens in titles are fine.

But I would like to have tokens accessible for the url.

For example, I would like to setup a cck link, my profile. the cck field would be user/[author-id] and when the link is used, the proper replacement for [author-id] would happen.

Simple use case, but I think it gets the point accross

minus’s picture

I am also very interested in a function like this

I'm working on a project where I need a field with a default url. The client fills out the form, a combination of the default url and what the user submits should be the final url.

Default setting for the link field should be something like this: http://www.link.com/#, when the user submits his form, the field should be http://www.link.com/#*****, and displayed on the node like "go to website". I have tried to solve this with link 6.x-2.5 ut with no luck.

Really need this function and hope you can help me :)

Morten

minus’s picture

am I just stupid or can this be done differently? :D

jcfiala’s picture

Status: Postponed (maintainer needs more info) » Active

I don't know what you mean, and I know I don't know you well enough to tell if you're stupid. :)

That said, there's usually more than one way to do something, especially if you're willing to roll up your sleaves and do some custom coding. using hook_nodeapi and an appropriate hook, you could change the value of the url when it's being displayed on a given context. Similarly, you could try doing something like that in the theme layer, overriding the node template involved.

Although I think the idea of having a token-replace in a url is a neat one, it's not currently a prioritiy to me - getting the module released at 6.x-2.6 is top priority for me, and then I want to fix up my DME module for an official 6.x release.

Of course, if someone wants to submit a patch...

minus’s picture

:D

I just want a field in my form where the user submits a number, when the user submits his form the number he entered will be part of an url that is showed as a link on his node. It's like a combination of a default url and what the user submits. If the default url is http://www.link.com/ it will be http://www.link.com/123 after the user has submitted his form. Possible?

I have no php skills at all :-/

minus’s picture

I fixed this with views:

content field and select "Output this field as a link", add the url and Replacement pattern: http://example.com/[field_your_field__value]

SocialNicheGuru’s picture

is [field_your_field_value] a token or a specific field.

My original idea was around tokens in link.

Thanks,
C

minus’s picture

its a specific field, sry :(

k3vin’s picture

+1

k3vin’s picture

@minus: You don't really need an extra content field [field_your_field__value] to add a reference argument to a link. The easiest way is just use the custom cck link field and put your link there manually. For example reviews/209

With token like reviews/[nid] would be nice. So the user don't care about this field and will see only the final link. I hope this feature will implemented soon.

Edit: I see that token already works with this option in link url fields only for the node edit form:
[x] Allow user-entered tokens
Checking will allow users to enter tokens in URLs and Titles on the node edit form. This does not affect the field settings on this page.

Another way to create custom links is to use the "custom links" module :) ->http://drupal.org/project/custom_links

This module supports tokens in URL. So it's very flexible and easy to create automatically links.

minus’s picture

In my case, the content type is a car-ad, where users can create ad's for their cars and boats. The link field(content-field) is the "number-plate"'s number, when the user fill this out and the node is being viewd, the field is a link to the an official database where users can check the car for financial issues. Id that can be done with custom_links I'm pleased.

SocialNicheGuru’s picture

I read that I could use custom links module to add a token to the actual URL. But does that module setup a cck so I can theme each link individually? Or does it just add an additional link to $node->link?

Thanks,
Chris

k3vin’s picture

It adds additional links to "$node->link" for nodetypes. I think you can theme these links individually. Usually they are display after the body content.

tinem’s picture

Think I have the same problem as mentioned here but can't figure out how to solve it. Hope some one can help with code to use, please?

CCK field as link - why is [nid] not functioning dynamic?

On this post http://www.tinemuller.dk/drupal/node/1139 in the link after New Find it on: http://www.tinemuller.dk/drupal/node/1097/?querynid=[nid] I can't understand why [nid] is NOT functioning - do you?

If you change [nid] to the node 1139 like this http://www.tinemuller.dk/drupal/node/1097/?querynid=1139 it's functioning. Have used days to solve this without success but I'm sure it can be done.

I have made this selections http://www.tinemuller.dk/drupal/div/New_Find_it_on.gif

Do I need to make it with some PHP code and if yes can you suggest the PHP code?

Or do I need to make it selecting some of the possibilities further down on the site where Token is mentioned?

tinem’s picture

Version: 6.x-2.5 » 6.x-2.6
Priority: Normal » Critical
bredi’s picture

BUMP

I have the same issue/request.

I tried enabling "Allow Tokens" as well. But it doesn't work.

thanks

marcoBauli’s picture

similarly here "Allow user-entered tokens" does not have any effect.. opened a separated issue at http://drupal.org/node/561084

SocialNicheGuru’s picture

i am taking a look at the cck link and I see that I can add in a default cck link value. I was going to use php to try and fill in the value

user/uid

but how do I specify uid of node author:

$node->uid

Do i have to perform a node_load? does this work when someone is submitting the node for the first time?

tinem’s picture

#18

If this will never get to functioning with token [nid] what can be used instead?

jcfiala’s picture

Version: 6.x-2.6 » 6.x-2.x-dev
Assigned: Unassigned » jcfiala
Priority: Critical » Normal
Status: Active » Postponed (maintainer needs more info)

Okay, I wrote a couple of automated tests using tokens in the url, and it works fine. I used the [type] token, which returns the node's type, and the [author-uid] token, which returns the author of the node's uid, which should handle things for generating links to users and the like.

If you're continuing to have this problem with the latest version, I'll need more detail about how you've set up your field and what you're using as the link content.

mattwmc’s picture

Well, I'm looking for tokens in the url as well.

Specifically the file name.

Something like this:

http://www.mysite.com/template.php?src=/sites/default/files/[field_image-filefield-filename]

Is this possible?

jcfiala’s picture

It should be, assuming [field_image-filefield-filename] is a valid token. I'm feeding the value of the feed through the 'node' tokens from the token module, so if my tests work, this should too.

Again, assuming that that is a valid token.

mattwmc’s picture

Yes its valid, but it just returns the text: [field_image-filefield-filename] and not the filename.

Do I need to enable something to get it to work in cck fields?

Thanks for the reply.

jcfiala’s picture

Yes its valid, but it just returns the text: [field_image-filefield-filename] and not the filename.

Do I need to enable something to get it to work in cck fields?

Well, do you have the Token module enabled? And did you check the 'Enable Tokens' checkbox in the field configuration form? Those are the only two things that need to be set for it to work.

mattwmc’s picture

"And did you check the 'Enable Tokens' checkbox in the field configuration form?"

Where is this located? I don't see it under "Manage Fields."

Thanks for helping out.

jcfiala’s picture

Version: 6.x-2.x-dev » 6.x-2.9

Under the 'Manage Fields' tab for the node type, you click on the field's 'Configure' link, and that takes you to the form where you can set things - about halfway down the page should be an 'Enable Tokens' checkbox.

If you can't see the Enable Tokens checkbox, then you don't have the token module enabled.

mattwmc’s picture

I still don't see it and Token is enabled.

Here are the screen shots. Is it missing or am I just missing it?

Screen Shot of Mod Token enabled: http://www.cosmicbooknews.com/images/tokenenabled.jpg

Screen Shot of CCK field: http://www.cosmicbooknews.com/images/dpfield.jpg

jcfiala’s picture

@mattwmc: You're showing me the field of the 'Link Image' widget type. That's not provided by the Link module - you're in the wrong issue queue. I'm guessing this is some kind of filefield thing?

mattwmc’s picture

Oh, I thought this was for cck filefield links? Isn't that image field a file field?? I'm confused, lol.

So I suppose tokens can't be used then?

Oh, fudge. I see "project" says link now. I was just looking at the title of the thread I found while searching. Sorry, for being a pain. Newbie here.

jcfiala’s picture

Well, thank you for making a screen shot - that was helpful to realize what was wrong!

mattwmc’s picture

lol. Yeah, sometimes I don't know the correct "lingo" and use screen shots to get my point across -

Especially when I am trying to wrap my head around all these modules!

Gotta say, drupal rocks though! Just need a bit of patience! ha!

neilnz’s picture

Status: Postponed (maintainer needs more info) » Needs review
FileSize
1.08 KB

Sorry if I'm hijacking this issue a bit, but I'm having a problem that I can't use a token as part of the domain, as it fails the URL validation in link_validate_url() because of the token square brackets in the domain. Otherwise token substitution is working fine as-is (eg. in GET params).

I've attached a patch I applied that substitutes the tokens on node save before attempting to validate the URL. This fixes the problem for me, and in theory provides stronger validation than at present, as it checks what's in the token can form a valid URL.

nravens’s picture

I need to do something similar but don't have a clue how to do this... I have a content type called accommodation with a link field that should link to an external URL; https://www.nightsbridge.co.za/bridge/Search?bbid=*with a user entered page ID here*

This user page ID is a 5 digit number that completes the URL and this completed URL will go to the user's page on the external site.... The CCK link field only needs to have the 5 digit number entered to be added automatically to the first part of the hidden or uneditable URL. Then I also need to add another static/fixed 2 digit code (also hidden) after the user's 5 digit code... The 2 digit number is my affiliate code for the external site...

I've created a content type template, so is it possible to add some php code to achieve this? or can I do it with the link module? I don't know php really so don't know how to construct something like this in the page template...

Any advice?

Summit’s picture

Subscribing for #36, #37 is a new issue, right?
greetings, Martijn

3dloco’s picture

Thanks a lot Neilnz!

#36 worked for me (I am able to use tokens for the url).

neilnz’s picture

@3dloco, if it's all working out well for you, could you RTBC this issue for me?

Would be nice to get #36 upstreamed.

3dloco’s picture

Status: Needs review » Reviewed & tested by the community

:) thanks

jcfiala’s picture

Status: Reviewed & tested by the community » Needs work

Well, for one, I'd rather you created a new ticket than bring this one to life.

For another, I'm not really sure why we need this, and having the token be evaluated during the node validation instead of when the node is displayed is a little weird. How often do people need to have a token in the host portion of the link? Why would you need to do that?

neilnz’s picture

@jcfiala, the reason I needed it was so that our site's content editors could create links in prod or dev or wherever and have them point to the right place. Our site is part of a network of other sites that all exist in various environments, so we have a custom environment token that they can put in links to test them in a given environment, eg:

Link URL: http://[environment].mysite.example.com/some/path/to/somewhere

The problem is that this causes the URL to appear invalid, unless you validate it at least for the environment it was saved for (or substitute any tokens for some string that will always validate).

Note these links are going to other non-Drupal sites, so can't be node references or paths.

izmeez’s picture

@neilnz Comment #43 sounds close to what I am looking for and I am wondering if the link module by itself or in conjunction with others will do the job. I need to create a menu item that links to a static site and have it work relatively so it works on both the live and dev site and in a multi-site setup.

the link url is http://example.com/sites/example.com/html/content.htm

I imagine the link url will end up like
http://[environment]/sites/[environment]/html/content.htm
or
http://[sitename]/sites/[sitename]/html/content.htm

Is this possible?

greta_drupal’s picture

Tokens for URLs would be a great plus (actually an expected functionality). Great for making dynamic links to social media sites, for example.

dqd’s picture

Assigned: jcfiala » Unassigned
Status: Needs work » Closed (duplicate)
Issue tags: +field validation

Dear followers of this issue: 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, conflicting with each other randomly. I think, the right way is to find a maybe more complex but all embracing new 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. This will surely lead to a new branch