I am trying to add the current users ID as a suffix to a cck link field as the node is loaded. Am I pipe dreaming?
I've created a text field on the content type with the "base" url. I have a cck link field that is blank that I want to populate with the base url + the uid of the current user.
I created a rule that when "Content is going to be viewed" & is this content type THEN DO
"Load content by ID" with the token node ID of the "Content is going to be viewed" node THEN
"Populate node_to_be_viewed's field" with some custom php:
$baseurl = $node->field_survey_base_url[0]['value'];
$urltitle = 'Take the survey here!';
global $user;
$userid = $user->uid;
$concat = $baseurl . "?c=" . $userid;
return array(
0 => array('url' =>$concat , 'title' => $urltitle)
);The $baseurl variable is never set. How can I get the field info from the "Content is going to be viewed" node?
I have also tried:
$baseurl = [node:field_survey_base_url-raw];
$urltitle = 'Take the survey here!';
global $user;
$userid = [user:uid];
$concat = $baseurl . "?c=" . $userid;
return array(
0 => array('url' =>$concat , 'title' => $urltitle)
);I know that both code snippets are working (sans $baseurl) and that the $baseurl variable is not set correctly because I have hard coded it with a URL and I get the result I'm hoping for.
Comments
I was able to get my
I was able to get my objective accomplished via another method. For anyone who might find this while looking to solve a similar problem I'll talk a bit about what I found. I would love to hear anyone's input on the above because I think it could use some clarification.
I tried to use the tokens right in the actual fields instead of the PHP described above. I had two problems with this: 1) when I used a cck link field the tokens didn't pass the "is a url test" so I couldn't save it, 2) when I switched to a text field, I was able to save, but the URL I created would only have the correct data appended after the second node load.
I also found a D5 module with D6 patch called Tokenize (http://drupal.org/project/tokenize). This module was supposed to allow tokens in CCK fields. It didn't translate the tokens for me and I didn't know if the patch was broken or if I was just doing it incorrectly.
I thought I had it figured out with views, by loading the UID and the URL and using "Rewrite this output field" or "Output this field as a link" and "Replacement patterns", but the UID is only for the node author. To get current user you need to choose the "User" view type when you set up the view and then the URL from the node isn't available.
The method that worked for me was to use http://drupal.org/project/views_customfield. I was able to grab the current UID with php and the above method to get the final result I wanted.