Coloring a Drupal role
NeoID - March 9, 2009 - 10:03
Hi,
Is there a module or easy way to assign a color to a role/group/rank so that all members of that group or rank have a special colored username?
Hi,
Is there a module or easy way to assign a color to a role/group/rank so that all members of that group or rank have a special colored username?
_
No module that I know of, but you can do it pretty easily. Override the theme_username function in your template.php file and style however you wish.
_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.
That would mean I'll have to
That would mean I'll have to hardcode either the username or role to a specific color.. not a very good solution... :/
There is a new feature at
There is a new feature at http://drupal.org/project/realname where you can add an image to each role ..
see http://drupal.org/node/388928
_
I'm not sure I understand-- do you want the user to be able to change the color or something?
_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.
I want to be able to do the
I want to be able to do the same as you can on every other modern forum; create a group, add members and (as an admin) give certain groups a special colored username...
_
Maybe http://drupal.org/project/user_badges is close to what you want? Otherwise, I still think theme_username is the way to go-- you can put any php you want there, so you can assign classes based on user roles then style/color them in css any way you like. You can also limit it to forum posts or let it follow the user throughout the site.
_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.
I've figured out that the
I've figured out that the below code works, but I'm trying to clean it up a bit and add a switch/case in order to check for more user roles.
So... I want to check if the user role is Moderator and if yes add a div-wrapper "moderator-role", but if the role is for example "Event" it should add a div with a class called "event-role"...
Anyone who knows how to clean it up a bit, it looks really messy if I copy/paste it for every user-role I want to check...
<?php
global $user;
// Check to see if $user has the administrator role.
if (in_array('Moderator', array_values($user->roles))) {
function phptemplate_username($object) {
if ($object->uid && $object->name) {
// Shorten the name when it is too long or it will break many tables.
if (drupal_strlen($object->name) > 20) {
$name = drupal_substr($object->name, 0, 15) .'...';
}
else {
$name = $object->name;
}
if (user_access('access user profiles')) {
$output = '<div class="moderator-role">' . l($name, 'user/'. $object->uid, array('attributes' => array('title' => t('View user profile.')))) . '</div>';
}
else {
$output = check_plain($name);
}
}
return $output;
}
}
?>
I found a nice way to do
I found a nice way to do this, however, instead of printing the role for the user currently logged in, how can I modify it in order to affect the current member (in the theme_username function)?
<?phpforeach ($user->roles as $role)
{
if ($role == "authenticated user") {
$newrole = "role-";
}
else {
$newrole = $role;
}
$roleClass .= t("%role", array('%role' => $newrole,));
}
?>