I have a problem with the views argument PHP-Validation:
I want the PHP-Code be "TRUE" if the argument/USER-ID is the same as the value of the CCK-Field "Userreference" (I named it "field_privacy" in my examples).
(What i expect: every user should see all nodes which are marked by the Userreference with its name/uid. And later a bit more complex ...)
I have set up a Views-argument with "Content: Userreference".
In a Drupal-Block i have this working PHP-Code:
global $user;
if (arg(0) == 'node' && is_numeric(arg(1))) {$node = node_load(arg(1));}
if ($user->uid == $node->field_privacy[0]['uid']) {print '<p>TRUE</p>';} else {print '<p>FALSE</p>';};
If i paste this similar(?) code into the views-argument PHP-Validation it won't work any more:
global $user;
if (arg(0) == 'node' && is_numeric(arg(1))) {$node = node_load(arg(1));}
return $user->uid == $node->field_privacy[0]['uid'];
or with the User-ID als argument:
return $argument == $node->field_privacy[0]['uid'];
If i take a number/Uid, for example:
return $user->uid == 12;
or
return $argument == 12;
everything is working fine. Of course, "12" should be the value/uid of the nodes CCK-Field "Userreference" ...
(If i use the "Basic Validation" instead of the "PHP-Code", everything is working as expected ... so what's the similar PHP-Code to the Basic-Validation? I want a bit more complex validation later on ... )
What's wrong? How to get the value of the CCK-Field into my PHP-Code?
Thank you for any help!
Tobias
Comments
You can do
You can do
print_r($node->field_privacy[0]);
to see the actual structure of the userreference field (i don't remember it off the top of my head).Also-- be aware that this is not real access control. Whether or not nodes get listed in a view does not affect their 'viewability' anywhere else. That is, people will still be able to random browse nodes by entering their URLs directly into the browser (ie site.com/node/5, site.com/node/1000, etc).
Thank you for your reply! The
Thank you for your reply!
The following code is working in a block (showing me the Uid of the nodes userreference-field):
So i expected
$node->field_privacy[0]['uid']
to work in views, too ... but it seems it does not?!(The real access control is another problem i solved already ... :-)
_
hmmm, maybe try:
... no, it's not working
... no, it's not working either ... :-(
_
Can you paste your views export into the thread?
My views export
"field_privacy" is the name of my CCK-field "userreference" ...
Did you ever get this
Did you ever get this working, with being able to access your CCK field in your views argument validation?
No, i'm sorry .. i dropped
No, i'm sorry .. i dropped this thing after that and looked for other solutions not similar to this ...