Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Is there any way to set a border color to every profile picture displayed all over the website depending on the role of the user?

I was trying to do it at least on the user profile image and on the User picture block module image following this instructions Custom node color from role but I ended in nothing.

Note: I display the profile pictures in a user search view, in the forums and in a block that display the latest forum comments.

share|improve this question

2 Answers 2

Try hook_preprocess_user_picture() in your template.php

function MYTHEME_preprocess_user_picture(&$vars) {
    $account = user_load($vars['account']->uid);

    foreach ($account->roles as $role) {
        $vars['classes_array'][] = 'role-' . strtolower(str_replace(' ', '-', $role));
    }
}

Each user picture should then have the role-rolename classes added to it.
It is similar to Clive's answer you mentioned, but different hook.

share|improve this answer
    
Sorry but this is not working, my user pictures are displayed using views (a list of users), profile (using a DS module template), forums (author pane) and user-picture-block module so all of them have classes different that "user-picture", well in fact one does but it doesn't get the "role-" class anyway... none of my pictures are getting the role, neither if you go to edit a user (with the admin 1)... –  warmth Nov 15 '12 at 13:47

I partially solved the problem with this:

function MYTHEME_preprocess_html(&$vars){
    global $user;

  foreach ($user->roles as $role) {
    $vars['classes_array'][] = 'role-current-' . strtolower(str_replace(' ', '-', $role));
  }

  if(arg(1) && arg(0)=='user'){
      $account=user_load(arg(1));
      foreach ($account->roles as $role) {
            $vars['classes_array'][] = 'role-visited-' . strtolower(str_replace(' ', '-', $role));
        }
  }
}

with this CSS:

.role-current-beta-tester .content_left .user_picture_block img,
.role-visited-beta-tester .user-profile .field-name-ds-user-picture img{
    border: 17px #019E96 solid;
    background: white;
}

.role-current-moderator .content_left .user_picture_block img,
.role-visited-moderator .user-profile .field-name-ds-user-picture img{
    border: 17px #37A962 solid;
    background: white;
}

.role-current-administrator .content_left .user_picture_block img,
.role-visited-administrator .user-profile .field-name-ds-user-picture img{
    border: 17px #517180 solid;
    background: white;
}

.role-current-usuario-profesional .content_left .user_picture_block img,
.role-visited-usuario-profesional .user-profile .field-name-ds-user-picture img{
    border: 17px #8A101C solid;
    background: white;
}

.role-current-usuario-no-profesional .content_left .user_picture_block img,
.role-visited-usuario-no-profesional .user-profile .field-name-ds-user-picture img{
    border: 17px #A8CE3D solid;
    background: white;
}

but that only works for the border of the picture displayed by the user-picture-block module and the picture of each user's profile (formatted with Display Suite). I still have the problem of the forums, my user search view and a small block that display user's latest comments on the forums (the default one of Advanced Forum module).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.