Parasolx

Professional in Drupal web development, theme designing, consultation and training

[Snippet] Getting all permission list index based on roles

09 Mar 2014 - 02:32 pm

Drupal handle permission through roles base assigning to user. One user could apply multiple roles. Each of roles specified various permission define in hook_permission(). To get list of index for all permission for one user, we could used this snippet.

<?php
  $roles = array(3 => 'Project Manager');
  $roles = $user->roles;
  $permissions= user_role_permissions($roles);
  print_r($permissions);
?>

Then by using user_access, we can define custom arguments like below:

<?php
if(user_access("create project content")) {
 print '<a href="/node/add/project">New Project</a>';
}
?>
Kategori: 
Tags: 
snippet
user_access
roles
permission