I'm building a website on Drupal 7 which will be accessible only to registered users. A taxonomy term is referenced to the user account. I need to add a body class based on that taxonomy term so I can personalize the theme's look depending on the logged in user.
2 Answers
In your custom module implement hook_preprocess_field().In the given code I am adding a taxonomy term field with uid as class,you can change to your requirement.
function mymodulename_preprocess_field(&$variables) {
global $user
if($variables['element']['#field_name'] == 'your_taxonomy_term_name') {
dpm($variables);
dpm($variables['classes_array']);
$variables['classes_array'][] = $user->uid;
}
}
Here is how I did it.
function mytheme_preprocess_html(&$variables) {
global $user;
$user = user_load($user->uid); // Load user
$variables['classes_array'][] = $user->field_myfield['und'][0]['tid'];
}
It will output the tid not the term name that is being referenced in the user account.