Jump to:
| Project: | Content Construction Kit (CCK) |
| Version: | 6.x-2.7 |
| Component: | userreference.module |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
Hello,
Thanks to everyone in this great community. I am new to Drupal and make my first steps in understanding.
So far I could figure out every solution with the infos I found here. But not in this case.
I use CCK and the USER REFERENCE modul/field. When I enter the configuration of that field in my content type I see the option 'Default Value' and the suboption to enter php code to define the default value.
That is exactly what I need (I think).
What code would I have to enter there to select by default the currently logged in user.
Can anybody help me with this code ? I have no clue about php
Below the PHP default value entry field there is the following hint:
"Advanced Usage Only: PHP code that returns a default value. Should not include
<?php
?>array(
0 => array('uid' => value for uid),
// You'll usually want to stop here. Provide more values
// if you want your 'default value' to be multi-valued :
1 => array('uid' => value for uid),
2 => ...
);
Using devel.module's 'devel load' tab on a story content page might help you figure out the expected format."
Thank you so much ... I hope I learn fast to be able to contribute back to the community soon ...
Comments
#1
This works:
global $user;
return array(0 => array ('uid' => $user->uid));
#2
And what about autofilling additional "profile_" -entries.
Example:
Registered user has profile information:
first name(profile_firstname)
last name(profile_lastname)
How can i make for example the first name a default field value?
Tried several approaches but the field stays empty :(
#3
A word of caution - the person *creating* the field has to have any roles that are defined as requirements on the field, otherwise saving the field definition fails the validation code. Even when you are user 1.
There really should be a simple checkbox in the Default Value block to select the current user as the default.
#4
This is super helpful--
I have a modification of the question:
how can i FORCE the node being created to be user referenced to a certain user id..
for example-- i may want certain users to only be able to reference themselves or other users in a group or category i make up..
Using the code from #1 works to set the default value, but what if i want to set the allowed values?
thanks