Panels allows selection rules to be created with custom PHP code (disclaimer: I know this approach is insecure and should be avoided).
When adding PHP code as a selection rule, the helpful description states:
Access will be granted if the following PHP code returns TRUE. Do not include . Note that executing incorrect PHP-code can break your Drupal site. All contexts will be available in the $contexts variable.
I made a function in a custom module to use for the selection rule:
function mymodule_selection_rule_is_location_set() {
global $user;
$user_fields = user_load($user->uid);
if (isset($user_fields->field_acc_location['und']['0']['lat'])) {
$location = $user_fields->field_acc_location['und']['0']['lat'];
}
if (empty($location)) {
return FALSE;
}
else {
return TRUE;
}
}
However, when I set the selection rule as shown below, the selection rule is not triggered even when there is a value for $location
and the function returns TRUE
(confirmed with devel module).
Evaluates false as a selection rule even when the function returns TRUE
mymodule_selection_rule_is_location_set()
To get it to work, I had to write the selection rule like this:
Evaluates correctly
if (mymodule_selection_rule_is_location_set()) {
return TRUE;
}
My question is why do I have to write it like the latter rather than the former?
;
, could that be the problem?;
or not.