So I was using CCK link field to set a link for each user in their profile.
I was using the placeholder token {author-uid] and setting the default value to: My profile usr/[author-uid]
So if I am user 26. if someone where to click on “View my profile” they would be taken to user/26
Another example is
Add me as your friend which would like to
/add/[author-uid]?destination=user/[author-uid]
When I view the nodeprofile, it is fine.
usr/26 for View my profile
/add/26?destination=user/26 when someone else views my profile
However when I have this field in a view using the view module, I instead get “usr/” with no number. When I print out the value for the link I get “user/[author-uid]” It looks like [author-uid] is not interpreted at all.
Is there another way to create a link to an internal page that is created for each user like usr/uid. So in a membership directory, each user will have this link so others can click on it and see their profiles. I am using views for the membership directory
I am using node profile and views. The latest for both on 5.6. It wasn't working when I was using 5.5 and one rev back of these modules either.
Thanks,
Chris
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | full_object_fix.patch | 728 bytes | populist |
Comments
Comment #1
socialnicheguru commentedWhen I use a token for a default value for the url, the substitution for the value is not made in the view.
Comment #2
socialnicheguru commentedI think this is a problem with the token substitution for a cck link as default in a View
Comment #3
vivianspencer commentedI'm getting exactly the same problem
Comment #4
NukeHavoc commentedI've run into the same sort of problem with Link CCK and tokens in both Blocks and Views. In my case, I've got a simple "Link" content type that looks like this:
Title: My Great Site
Web Address Title: [title]
Web Address Link: http://www.mygreatsite.com
If I'm looking at the node, then this works; the [title] token is replaced by the node title. However, if I'm looking at a View or a Block, "Web Address" appears blank. The only exception is when I'm on the node for that particular link; in that case the title appears properly in the Block.
I'm assuming that it's not supposed to work this way, and that it's a problem with CCK's implementation of tokens.
Comment #5
socialnicheguru commented#4 description is exactly right.
But this is a problem with cck link and token. It has driven me CRAZY. anyone know how to fix it.
So it was suggested that I not use CCK link for this, but just do it on the theme level in the view.
http://drupal.org/node/250007
Chris
Comment #6
gregglesCould someone start with:
1. Install a bare Drupal core site
2. ...
And step me through everything to get to:
I expect to see Foo and instead I see Bar!
As it stands, I have no idea exactly which contributed modules are involved or what is/isn't happening.
Comment #7
NukeHavoc commentedHere you go.
Summary
I think there's a problem with the token_replace function in token.module not having the full node information it needs to do the token replacement. I don't know, however, if this is an issue with CCK Link not passing it the right information in the form of the node object, or a problem with token assuming it's getting one kind of node when in reality it's getting something else. Full details, and a workaround hack, follows.
Recreating the problem
Install the modules
I recreated this problem using a clean install with the following modules:
* Install Drupal 5.7
* Install Views 5.x-1.6
* Install CCK cck-5.x-1.6-1
* Install CCK: link-5.x-2.1
* Install Token: token-5.x-1.10
I also installed Devel 5x-dev after the fact to analyize what was happening.
Create the "Link" content type
* Administer > Content Types > Add content type
* Use all the standard options for the content type (title field: Title, body field: Body, etc.)
* Edit the new content-type.
* In the "Create new field" group, specify the name "web_address" as the name
* Choose "Link: Text Fields for Title and URL" from the as the field type.
* Click the "Create field" button.
* Go to "Manage fields" tab.
* Click configure on web_address.
* Set "Link Title" to "Static Title". In the field for "Static Title", specify the token "[title]".
* Click to "Display fields"; use the defaults: Label/Above; Teaser/Default, as link with title, Full/Default, as link with title
* Add three new nodes using that content-type.
Create the View
* Create a view called "Links View"
* Page:
** Provide page view [checked]
** URL: links
** Provide Page View
** View type: Table view
** Nodes per page: 50
* Fields
** Add a field: Link (web_address)
*** Label: Title
*** Handleer: Group multiple values
*** Option: Default as link with title
*** Sortable (none)
*** Default Sort (none)
** Add a field: Node Body
*** Label: Teaser
*** Handler: Teaser
* Create a Filter "Node:Type"
** Specify operate as "is one of" with a value of "Link".
For other Views, I also do an argument based on taxonomy (either numeric or text) but it isn't necessary for this experiment.
Load the View
Now load the view. What you should see is:
* Title Column: Displays nothing. It *should* be showing the node title, passed via the token.
* Teaser: Displays the "web_address" label, but without the web_address title. Also shows teaser from node. What it should show is the label with the title of the node, passed via token, as well as the teaser.
If I go back to the Link Content Type and set "Title" to "Optional", and then manually enter a "web address title", then that title will show up correctly in this view. It only breaks when we tokenize things.
Looking at this via Devel 5.x-dev's "Dev Queries" tab, i can see it's using this query to construct the view:
I can also see the objects its returning:
Code Delving
In trying to debug this, I started with the CCK Link and the link.module. At line 619, we have this logic:
I confirmed that this code is triggered, and it does call token_replace, which is a function wihtin token_module. The problem is that this simply doesn't work; while the arguments for token_replace appear to be correct, the function returns a blank value. This causes $title to be blank. $title is what's outputed to the screen, so that's why we lose the title.
As for why it breaks, I looked at token_replace at line 145 in the token.module:
token_get_values is supposed to go out and get the list of replaceable tokens based on the object, which in this case is the node that was passed to it as part of token replace.
If I use Devel's dvr function on $full, I get the list of tokens and values for each node (I'm limiting it to the first node for brevity's sake:
As you can see, Title (Token #11) comes up blank. Interestingly, when I look at the node view for this link, the token *does* work. When I look do a dvr($full) when looking at the node I see that, sure enough, the title value (Token #11) for the token has an entry: [11]=> string(21) "Model Rocket Mission".
So here's what I think is happening.
* When looking at a View or a Block, the node information being passed by the line "$title = token_replace($title, 'node', $node);" is not what "token_replace" is expecting. See my break out of the View node objects for a list of what's included in the View-generated node.
* token_replace wants the full node, NOT just the abbrevated node that Views assembles for its purposes.
I tried two things to fix this. First, I tried passing the full node to token_replace, by doing this:
That didn't work, so clearly my theory is a little wonky. However, when I went into the token module, and tried the same trick, *it did work*:
$object = node_load($object->nid);
This caused the web_address title token to be replaced correctly in every instance, regardless of whether I was looking at a Block, a View, or a Node.
I'm not fluent enough in CCK, Tokens and Views to be able to say which one's malfunctioning -- is Token wrong for wanting a full node? Is Link doing something wrong when passing the argument? -- but I hope this clarifies exactly where things are falling down.
Comment #8
ambereyes commentedI had a similar problem. I tried using a static title field with [title-raw], the view was a complete blank. I then modified my content type and added the token as a default for a required field, and now the urls list but not the title unless I typed it in - no token replacement.
I then tried the suggestion from #7, and patched the token_replace function within the token module - it works! My view now lists the title as a link.
Can this be rolled into a patch? Or is there other issues that need resolved?
Comment #9
ahojchris commentedSeeing the same issue.
Using CCK + imagefield + link + views. The Content type I've specified is fairly simple, as is the view: one image field and one link field for the content type, and a basic "show all content of this content type" view.
In the link attributes under Link Title, I'm selecting a static title with a token for the "Fully formatted HTML image tag" (i.e. [field_FIELDNAME-view] ) ...
Token is on and works with the non-cck tokens (i.e. [nid]) so obviously some of the token functionality works. Just seems to ignore tokens for CCK fields and passes them straight through as hard-coded text.
I suppose a work-around is to define some views functions in PHPTemplate to create links... Does anyone have an elegant workaround to share while this (hopefully) gets addressed?
Comment #10
populist commentedI had the same problem and the node_load bit from #7 worked wonderfully. I rolled a patch.
Comment #11
gregglesI believe this will break token under other circumstances. Whatever is calling token_replace should make sure that the $object is properly populated prior to calling token_replace.
Comment #12
scooper@drupal.org commentedYes, it did break for me in other circumstances:
I had a similar problem - my CCK link field was blank when displayed in a context sensitive view embedded in another CCK node. The revised code from #7/#10 fixed it perfectly.
However, this patch broke my use of tokens to generate node titles using module Automatic Nodetitles, which works fine with the original token_replace function.
And, it causes a SQL error when using the node_import module to import data into a CCK link field.
So a check needs to be added to the patch:
if (node is loaded)
$tempobject=$object;
else
$tempobject = node_load($object->nid);
Does anyone know how to code this check before calling node_load()?
I agree that a better solution is to properly populate $object prior to calling token_replace, but in the meanwhile...
Comment #13
gregglesYes, the proper way to do this check is just not to do it :) The calling function should fully load the node prior to passing it to token.
So, this needs to be fixed in link, then - reassigning.
Comment #14
ambereyes commentedOkay, in a act of total frustration ... I did the following starting at line 618 of the link.module.
It ain't elegant, but it works. If someone has a better solution, I am all ears.
Katrina
Comment #15
NukeHavoc commentedI found that the hack in #14 only worked if the node's title field was included as part of the View; if I didn't include the node title in my view, then CCK's link title tokens displayed nothing.
Comment #16
gregglesI believe this is a duplicate of http://drupal.org/node/206077
The code in that issue has not been released yet, but you could test out the latest 5.x code in order to get this fixed.
Specifically, the commit which fixed this was http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/link/link.m...
@quicksketch - can you make a new 5.x-2.2 Link release so that folks can use that? If not, I believe that the 5.x-1.x-dev tarball is the same code, right?
Comment #17
quicksketchAh, thanks greggles. I didn't realize that change wasn't in the 2.1 version. I'll roll out a new version shortly.
Comment #18
NukeHavoc commentedAfter spending too long trying to debug this, I finally realized I was having a forest for trees moment. What I'm trying to do is use the node 'title' in place of the url field 'title' by passing a 'title' token. It's the 'title' bit that threw me.
We are absolutely right that token_replace expects to be passed a full node ... but my earlier attempts tried to pass it the full node for the *title* substitution NOT the *url* substitution. That'll fix the problem with broken tokens in the title, but hey, that's not what I was trying to do. :)
So in order to get this to work, we have to fix link.module so that it always loads the full node whenever it tries to do a token substituion for "title" AND "url".
Here's the fixes I propose for link.module:
Change the "url" token bit on line 581 from:
to:
And then do the same for "title" at line 618 from:
to:
This works on my development system. It doesn't muck with the token.module, so it shouldn't have the ill effects that folks saw with my earlier hack, and it passes the token module exactly what it's expecting (which is the full node).
Please try it out and let me know if you run into any snafus.
Comment #19
quicksketchNukeHavoc, as greggles suggests, try out the dev version of link.module, where a nearly identical solution was posted some time ago.
Comment #20
NukeHavoc commentedheh. If only I'd found that earlier report a few weeks ago. :) That patch worked like a charm.
Comment #21
quicksketchGreat. I'll marked this issue "fixed", and I'll get out a new version of link shortly.
Comment #22
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #23
charlie-s commentedI see this is over a year old, but I'm having exactly this problem.
Using Drupal 6.15, this is a week-old installation with nothing hacked. I am actually able to see the Link output in a Page View but not in any Block View. Using all current modules (Link 6.x-2.8 and not dev).