0

I have a page view with a menu tab and URL looks like my-site.com/user/%/my-view

I use return $argument == $GLOBALS['user']->uid; for default argument. And then I would like to limit the argument to only the currently logged-in user’s uid but how can I exclude admin role (uid=1)?

After reading this article I tried this but didn't work.

global $user; 
if($user->uid != 1){
return $argument == $GLOBALS['user']->uid;
}

What I need to achieve is: Admin role(uid=1) can see my-site.com/user/%/my-view for all users but the rest of the users can see only the view according to their uid.

1 Answer 1

0

That is a basic PHP problem, it does not concern Drupal so much. You want to admit access to the admin user always, so you will want to exclude that user's user id of any checks. However, your logic is wrong. The correct version would be

global $user;
return ($user->uid == 1 || $user->uid == $argument);

Which firstly returns true if the user is the admin user and secondly returns true if the user id matches the argument.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.