I want users to easily modify the layout of a node by selecting options in a 'Layout' field that the node contains. The field is a entityreference field referencing taxonomy terms. (For example, the user can select term 'hide-images' and the body class 'hide-images' will be used in the css to hide images.)
I have found this code that sets the first value of a field as body class. But how can I add all field values (taxonomy terms) as body classes?
/**
* Implements hook_preprocess_html
*/
function THEME_preprocess_html(&$vars){
// Check if on an article node page
if($node = menu_get_object('node') && $node->type == 'article'){
// Get field values
if($term = field_get_items('node', $node, 'field_layout')){
// Add first term value to body class
$vars['classes_array'][] = drupal_html_class(reset($term));
}
}
}