Display $tabs based on Role Type

drupal_branding_2012I came across an issue today whereby questions created by a certain user were editable by other users. The ‘view’ and ‘edit’ tabs were visible but the preference was that they would only be visible to the creator of the question. I checked the permissions page (admin/people/permissions) but everything was okay since each role could edit its own content but not all content.

To solve this problem I made use of the following code:

global $user;
if ($node->;uid == $user->uid || in_array(‘administrator’,$user->roles)){
if ($tabs = render($tabs)): ?>;

<!–?php endif; } ?–>;

This code simple says the tabs will be displayed if the current logged in user is the creator of the question node or is the super administrator. This code can be used for other kinds of content types.

April 28, 2014

Posted In: Information Technology

Tags: ,

Leave a Comment