- 2011-09-01: Building an Unfuddle to Drupal Casetracker import module using Migrate
- 2011-08-28: Back from DrupalCon London and its WSCCI code sprint. Wow.
- 2010-12-21: Madame Figaro brand new site by OSInet and others
- 2010-08-16: France.FR is back online with OSInet and Typhon
- 2010-06-15: the new http://www.franceculture.com/, which OSInet helped reach its performance goals, is now online
- 2010-06-13: the OSInet Features Server is live
- 2009-11-29: mongodb_watchdog module created by dereine, ported to D7 by me in about half an hour, and migrated in a larger MongoDB project by damz before the hour ended. Wow...
- 2009-02-03: the new Drupal-based site for the golden jubilee of the french "Ministère de la Culture", which OSInet helped build, is now online
Drupal admin: displaying user roles on the account edit page
Some sites may wish to display to users what their roles are. Here is a small module allowing just this.
Drupal user roles are typically seen only by the administrator when editing a user's account. As of 4.6.3, there seems to be no simple way to have them displayed to user when they access their own information in a theme- and theme-engine-independent way (a PHPtemplate-dependent trick is explained on drupal.org).
So the simplest way appears to be a module implementing hook_user.
This can be added to an existing module, or coded on its own.
In this case the code is supposed to be implemented as csroles.module,
meaning it is in a module of its own that has to be activated from
http://www.example.com/admin/modules
<?php
// $Id: csroles.module,v 0.1 2005/08/24 00:41:00 FG Marand $
// Sample code due for the upcoming OSInet helpdesk support module for Drupal
function csroles_help ($section = '')
{
$output = '' ;
switch ($section)
{
// The description found on the admin/system/modules page.
case "admin/modules#description":
$output = t ("Allows for the display of an user's roles on their profile page") ;
break;
// The module's help text, displayed on the admin/help page
// and through the module's individual help link.
case "admin/help#customersupport":
$output = t ("Allows for the display of an user's roles on their profile page") ;
break ;
}
return $output;
}
function csroles_user ($op, &$edit, &$user, $category = NULL)
{
$ret = NULL ;
switch ($op)
{
case 'view':
{
$ret = array ('account' => t('Personal information')) ;
break ;
}
case 'categories':
{
$ret = array
(
array (
"name" => "csroles",
"title" => "user roles",
"weight" => 1)
) ;
break ;
}
case 'form':
{
// When user tries to edit his own data:
if ($category == 'csroles') // default: account
{
$ret = array
(
array
(
'title' => 'You have been assigned roles:',
'data' => '<ul><li>' . implode ('</li><li>', $edit ['roles'])
. '</li></ul>',
'weight'=> 0,
)
) ;
}
}
}
return $ret ;
}
?>For site admins wishes to display the same information in a block without
adding a module to an already overloaded
site, there is a shorter way: create a custom block in
http://www.example.com/admin/block/add,
setting the input filter to PHP code, and type:
<?php
global $user ;
print ("<ul>\r\n") ;
foreach ($user->roles as $role)
{
print (" <li>$role</li>\r\n") ;
}
if ($user->uid == 1)
print (" <li><em>sysop</em></li>\r\n") ;
print (" </ul>\r\n") ;
?>Tagged for drupal, sample code, and user roles in Technorati.





Is it possible to display
Don't display 'authenticated user'
foreachloop:<?php
global $user ;
print ("<ul>\r\n") ;
foreach ($user->roles as $role)
{
if ($role != 'authenticated user') // mask that role
{
print (" <li>$role</li>\r\n") ;
}
}
if ($user->uid == 1)
{
print (" <li><em>sysop</em></li>\r\n") ;
}
print (" </ul>\r\n") ;
?>
display user access
I would like to display all the common pages and modules, to which the user has access, based on his roles. How do i accomplish it.
Thanks
Shah
Basically you don't
Due to the menu inheritance system, that list would basically be infinite, or very large, since any path with additional components to a valid path is also a valid path.
So you probably want to only display part of that list of paths (pages). The question then becomes : exactly which pages would you display in that list ? If it's nodes, it can still be a very long list, as you can have up to 4 billion nodes on a Drupal 6 site.