Posted by gadams on March 30, 2011 at 6:44pm
23 followers
| Project: | Link |
| Version: | 7.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
| Issue tags: | field tokens |
Issue Summary
This references issue http://drupal.org/node/1065666 titled: "Link 'Title' as Token?"
I think it would be awesome to integrate Tokens (possible using Entities api) so that it could be possible to use [node:link-title] for URL Aliases, Node Auto Titles, etc...
[node:link-path] is the URI
[node:link-title] is the title for the URI.
Comments
#1
Subscribing
#2
Subscribing
#3
I believe all that needs to be done is replace link_token_list() and link_token_values() with the following:
<?php
function link_token_info() {
$info['types']['link-field-field'] = array(
'name' => t('Link field'),
'description' => t('Tokens related to a link field instance.'),
'needs-data' => 'link-field-field',
'field' => TRUE,
'module' => 'token',
);
$info['types']['link-field-field-value'] = array(
'name' => t('Link field values'),
'description' => t('Tokens related to a link field values.'),
'needs-data' => 'link-field-field-value',
'field-value' => TRUE,
'module' => 'token',
);
$info['tokens']['link-field-field-value']['url'] = array(
'name' => t('URL'),
'description' => t('The link field url.'),
);
$info['tokens']['link-field-field-value']['title'] = array(
'name' => t('Title'),
'description' => t('The link field title.'),
);
return $info;
}
function link_tokens($type, $tokens, array $data = array(), array $options = array()) {
$replacements = array();
$sanitize = !empty($options['sanitize']);
if ($type == 'link-field-field-value' && !empty($data['item'])) {
$item = $data['item'];
foreach ($tokens as $name => $original) {
switch ($name) {
case 'url':
$replacements[$original] = url($item['url']);
break;
case 'title':
$replacements[$original] = $sanitize ? check_plain($item['title']) : $item['title'];
break;
}
}
}
return $replacements;
}
?>
(Note: this assumes that the patch from http://drupal.org/node/691078 gets into the token module)
#4
Patch attached with my version of Token support, which is basically the same but with an extra 'view' token for a simple formatted link.
#5
I didn't read through the patch, but I did apply it.
I expected to be able to use:
[node:field-name:title]
[node:field-name:url]
or at the least
[node:field-name:value]
None of these supplied me with a valid token.
#6
Everett,
They worked fine for me, have you applied the Token module Field Tokens issue patch (http://drupal.org/node/691078?page=1#comment-4594082)?
Cheers,
Deciphered.
#7
I too do not see any tokens available for link fields. I'm using Entity API module rather than the core patch. I do see tokens for other field types.
#8
Dalin,
I don't know about any core patch, but you do require the Token module and Token module patch.
Maybe try that.
#9
@dalin
I am using token 7.x-1.x with the field tokens patch applied. I can access tokens for some of the other fields on my node, but not the link field.
If I go to node/1/devel/token the field is listed as
[node:field-name-of-link-field
But, I don't seem to be able to access anything from that token with :value], :title] or :url]
#10
Hey Everett,
While the dev module doesn't display the expanded set of tokens, they do exist. If you are using auto nodetitle or pathautho, you should see the expanded set in those places.
#11
Where do I find the token list with the auto_nodetitle module? When I edit the content-type and the auto nodetitle tab is active I don't see anything that would indicate a list of tokens.
note: I am using a screen-reader, so it is possible that this feature of auto nodetitle is not accessible, I can file a bug against that module if this is the case.
#12
Crazy, I just looked again and they are there. Thanks for the heads up.
#13
no problem :)
#14
#15
I get the tokens now with that patch to Token module. Odd that I didn't need that to use tokens for other field types.
I think Token module isn't doing enough cache clearing.
This patch works for me, though I didn't do a technical review so I won't mark it RTBC.
#16
Oh this was already RTBC, so I'll return it to that.
#17
#18
I am using Token 7.x-1.0-beta7 and the Link 7.x-1.x-dev from Oct. 28. I see the field token but it does not have the tokens for the title or url components. I have cleared the cache after upgrading. (The Token patch referred to in an earlier comment no longer works with the current Token module.) Has anyone tried this with the latest and had it work?
#19
http://drupalcode.org/project/link.git/blob/refs/heads/7.x-1.x:/link.module
patch not committed yet
#20
patch not working
#21
Looks like we've got a couple of options: wait for the Token module to resolve its architectural issues (see #691078: Field tokens) or try to get this done via the Entity API module's Entity Tokens module, which may have its own challenges. As it happens, the Date module is facing similar issues; there's a currently postponed issue over there summarizing the challenges (see #1103032: Re-Add Field Token Support).
I haven't tried Link fields with the Entity Tokens enabled yet; I did try to see how far I could get with core Token functionality and the Token module enabled, using the Examples module, the code in comment #3 above, and the Date module's tokens.inc as a template, but it doesn't look like I'll have any more success than the rest of you given the issues I cited.
#22
You can access the link title and url via the entity token module which is included in the Entity API module.
#23
Pathauto unfortunately requires the token module, and the token module + entity api tokens do not play nice together.
#24
What do you mean exactly? It works fine for me.
#25
http://drupal.org/node/1272560
#26
@jastraat what about #1272560: Entity tokens duplicates field tokens created by token module ?
@hackwater I don't think there's a need to wait till the issues you highlighted in #21 are fixed. Others modules aren't.
There's even a patch from @Deciphered, thought it needs review.
I expect what was needed #691078: Field tokens is available in Token 7.x-1.4.
#27
@mgifford - The duplication of all tokens doubles the number of tokens that the token UI has to handle and leads to a memory problem: http://drupal.org/node/1203018
#28
Subscribing
#29
Anything new regardind this issue? using token 1.5 and link 1.1 doesn't seem to provide token for the title or url.