0

I have a view called Map Items showing a list of map markers in a chart.

Info: I have 3 Accounts in my drupal installation called person1, person2, and admin.

I've set the contextual filter to Author uid: User ID from Logged in user. and its working perfectly, but what I want some additional setting that when there is no logged in user I could set person1's map item to show. Right now when there is no logged in user the view shows the map item of admin user and not person1.

How am I going to accomplish this?

2
  • in contextual filters instead of selecting User ID from Logged in user select php code and write some code like Aug 21, 2014 at 12:07
  • There is usually a setting in Contextual filters what to do if there is no valid argument, try to see if you can set a fixed value there.
    – prkos
    May 2 at 22:27

1 Answer 1

0

In contextual filters instead of selecting User ID from Logged in user select php code and write some code like

global $user;
if($user->uid > 0){
$uid = user_load($user->uid);

$roles = $uid->roles;
if(in_array('administrator', $roles)){
return 'uid of the logged in user';
//print_r($uid->roles['3']);exit;
}
else{
return FALSE;
}
}
else {
return 'return here person1 uid';
}
5
  • I'm new to drupal and I'm still in the process of learning stuff. So what do you mean by "return 'uid of the logged in user'; " What should I put there?
    – Richard
    Aug 26, 2014 at 2:36
  • return person1 uid means that you have to return the user uid of person1 here. Aug 26, 2014 at 4:10
  • Can you tell me how to do that? I'm a bit lost.
    – Richard
    Aug 26, 2014 at 4:51
  • How do I return the uid of the logged user, or uid of person1? How do I get the uid for a specific user?
    – Richard
    Aug 26, 2014 at 5:15
  • if the user is looged in you can get the id by using global $user; $uid = $user->uid; print $uid; or Simply pass $uid = 'numeric id'; Aug 26, 2014 at 11:21

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.