I created a content type and added a link field to it. I wanted the link title to use the node's title so I selected "Static Title" and tried both "[title]", and "[title-raw]". I then created a view in which I wanted to provide a block menu which lists only "title" that links to the link url. The actual view did not include the "Node:Title" field and therefore the note title was not available for the placeholder token in the link's title.
This may be a bug with the Token module or possibly the Views module as this may be an issue with other field types as well. But in my case it was specific to the Link CCK module which is why I'm posting this here.
In Summary:
Using the Placeholder Tokens [title] and [title-raw] are not available in views which do not include the Node:Title field.
The fix would need to come in one of mentioned modules to where it loads the node's data when a placeholder is found but is not yet loaded.
Temporary Solution:
To get the result I was looking for I had to require the Link Title on the Content Type, therefore requiring the user to enter the title twice.
Please advise if I should report this under another module.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | link_view_tokens.patch | 847 bytes | quicksketch |
Comments
Comment #1
lee20 commentedAfter further review this seems to be a "bug" with the token module (or atleast that is where the fix would be most useful).
THIS BUG SHOULD BE MOVED TO THE TOKEN PROJECT (I don't know how)
In the token module, specifically in token_node.inc within the function node_token_values is where I think the fix should be made. This function is passed an a (node) object. This function then translates the node values into the token values.
In my opinion, is the the token modules responsibility at this point to ensure the necessary values (the values that if offers for use to other modules) should be loaded. Here is the fix that I made which ensures that the node's title, created, changed, name, and type are available.
Comment #2
quicksketchWhen updating an issue, just change the "Project" select list to the module you want to transfer the issue to.
Comment #3
gregglesWell, your query has some security holes in it. The better way is to use the "%d" replacement mechanism in db_query to prevent sql injection - see http://drupal.org/writing-secure-code for more information. I think a better solution would be if (isset($node->nid) {$node = node_load($node->nid) }.
Beyond that, token module expects that the calling module has prepared the $node object with all the data that is normally available in those objects after a "node_load". Assigning back to link but I'm not sure tht's the right place.
Comment #4
jscheel commentedOk, it looks like link is adding it's values to the node twice. Once, it is getting added properly through cck, generating the key "field_field_name". But then, it's getting added to the node again, this time without a key. Here's the relevant part of a node_load():
I don't know enough about the cck api to say why this might be happening.
Comment #5
jscheel commentedWell, it seems like the token replacement only breaks when the link is in a view. I ran a quick test, below, in link_field_formatter(). I just removed all the keys that link adds to the node, and ran a basic token_replace test. It doesn't work:
Comment #6
jscheel commentedIt looks like token is dumping out to prevent infinite recursion. Not sure what's going on honestly. Anyone have any ideas?
Comment #7
gregglesThat's certainly possible. There were plenty of "token kills my site" bugs that were caused by the infinite recursion problem. So, we instituted that check. I didn't write it, just tested/committed it so I can't really speak to it. I think quicksketch might have some experience with it, though.
Comment #8
quicksketchI found the cause of the original bug (maybe the duplicate link data, but I think that's another issue). When displaying in a view, the full node isn't available. It's just the psuedo-node handed to us by views for efficiency. Because token requires a full node, we need to do node_loads if using token replacements.
I've committed this patch. Please reopen if you still experience the same issue.
Comment #9
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #10
jmlane commentedPatch works for me, although I patched the code by hand, as the line numbers didn't seem to add up in quicksketch's patch.
Great fix!
Jonathan M. Lane
OpenConcept Consulting Inc. http://www.openconcept.com/