Showing posts with label Users. Show all posts
Showing posts with label Users. Show all posts

Tuesday, June 29, 2010

Checking whether a user has a specific role...

Drupal 6 makes it easy to check whether or not a user has a specific Access Privilege.  It is indeed used in most modules, as it is essential and yields much power and flexibility in use.

What Drupal 6 does however NOT make trivial, is to check whether or not a user has specific role ( a named role, e.g. "administrator", "authenticated", "member" - whatever roles you may use).
How-to
<?php  global $user;

 
// Check to see if $user has the administrator role.
 
if (in_array('administrator', array_values($user->roles))) {
   
// Do something.
 
}?>

Here we use the default full array that each user has as an attribute - the collected roles of the user!  Note that this array is keyed, and the role names (not unique!) are thus kept in the values of the keyed array!
Why is this useful?
Well, let's suppose that you have a list of nodes (a blog-style for example), and these nodes in the listing are authored by different users - different users with different roles indeed!  Using the technique above, will enable you to theme the blog-entries of each user-role, making it easier to visually tell them apart on-page for the reader of the blog.

Saturday, May 22, 2010

Totally necessary modules...

The Modules that you will need for the typical Drupal 6 Installation... All modules below are oriented towards content and editing of this content - See other post for Developer modules.

All work in well-tested Drupal 6.x-installation, so go ahead - go wild - Install ONE, install ALL
  1. Everyday editing... WYSIWYG
  2. Better, richer content on your page, and the content fields and types you crave... CCK
  3. Control the display of your content; blogs, listings, detailed views, with or without pager, meeting certain criteria... Views 2
  4. File, image and media handling - A collection
  5. Create your own forms - replace the limited built in Drupal Contact Module... Webform