Set the Contextual Filter: Author uid. to a default user?

by Richard   Last Updated March 14, 2019 20:07 PM

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?

Tags : views


Answers 1


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';
}
harsh_behl_0007
harsh_behl_0007
August 21, 2014 12:20 PM

Related Questions


Updated February 28, 2018 21:07 PM

Updated May 26, 2016 09:03 AM

Updated July 20, 2015 13:03 PM

Updated January 12, 2017 08:03 AM

Updated May 02, 2015 23:03 PM