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.

Please follow and like us:

Leave a Reply

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

April 28, 2014

Posted In: Information Technology

Tags: ,

Leave a Comment