I have a content type event
containing a field called number_vip_pass
. An event has 20 vip pass and the number of vip pass decreases when someone takes one (via rules).
The problem is that, actually, users can take vip pass even when number_vip_pass = 0
. It makes the value of this field go negative.
I would like to hide the block (called vip_pass
) allowing people to take pass when number_vip_pass < 1
and I've found that you can hide it with the 'Show if the following PHP code returns TRUE' checkbox.
My question is : What PHP code should I put in there? I tried different ways to write this script but can't find the answer. I don't know how to get the field to compare it to 1 in the if statement.
Here is my code :
if(arg(0) == 'node')
{
$nid = arg(1);
$node = node_load(array('nid' => $nid));
if ($node->field_number_vip_pass < 1)
{
return FALSE;
}
else
{
return TRUE;
}
}
Have a nice day =)
Ok so I've found the answer on the net :
$node = menu_get_object();
return (isset($node->field_number_vip_pass[LANGUAGE_NONE][0]['value'])) ? $node->field_nbre_pass_vip[LANGUAGE_NONE][0]['value'] : FALSE;
I don't know why, I don't know how, but this works perfectly.
May be you need to change the code to be something like
if (count($node->field_number_vip_pass[LANGUAGE_NONE]) < 1)
{
return FALSE;
}