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?

  • in contextual filters instead of selecting User ID from Logged in user select php code and write some code like – harsh_behl_0007 Aug 21 '14 at 12:07
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';
}
  • 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 '14 at 2:36
  • return person1 uid means that you have to return the user uid of person1 here. – harsh_behl_0007 Aug 26 '14 at 4:10
  • Can you tell me how to do that? I'm a bit lost. – Richard Aug 26 '14 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 '14 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'; – harsh_behl_0007 Aug 26 '14 at 11:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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