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

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

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';
return FALSE;
else {
return 'return here person1 uid';
August 21, 2014 12:20 PM

Related Questions

Alter the moderation state in the Content view Drupal 8

Updated February 28, 2018 21:07 PM

Group items in Views by value in Field Collection

Updated July 20, 2015 13:03 PM

List of referenced entities appended to a node

Updated January 12, 2017 08:03 AM