Admin_views Module with multiple user

Module URL:  admin_views

We use this module to provide nice filtering features for our client. In few cases we share create different roles based on client request. Such as, This particular user can only edit his contents or specific content types. A good feature of admin_views is that it does considers user permission and renders admin links based on that. But one problem is that if the site has huge list of contents; its hard to find a single content from a list of thousand items.

To make this user intuitive, we want to show only user contents in Content Management but for specific roles we will show them all. To do that follow these steps:

1. Go to Views and open edit form for “Administration: Nodes” .  Admin_views module utilises this module.

2. Add a contextual Filter Author: uid  . Click on “Provide Default Value” and choose PHP code. Note: If you dont see php code in here then enable PHP filter module from Modules.

3. Now put following snippet in the “PHP contextual filter code” :

global $user;

if( in_array( 'administrator', $user->roles) )
  return 'all';
else
  return $user->uid;

4. Finally Save the views .

Thats it . Now only administrator can view entire list but for other roles only authored contents will be visible to logged in user.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s