Add class from field value to view mode
Handy for themers to have a field value as class in the section wrapper div classes. For example, if you want admins to easily change the color of a block/node using a dropdown interface.
// support for nodes (also in blocks)
function phptemplate_preprocess_node(&$variables) {
if (isset($variables['field_block_color'][LANGUAGE_NONE][0]['value'])) {
$variables['classes_array'][] = check_plain($variables['field_block_color'][LANGUAGE_NONE][0]['value']);
}
}
// support for beans
function phptemplate_preprocess_block(&$variables) {
if ($variables['block']->module == 'bean') {
if (isset($variables['elements']['content']['bean'][$variables['block']->delta]['#entity']->field_block_color[LANGUAGE_NONE][0]['value'])) {
$variables['classes_array'][] = check_plain($variables['elements']['content']['bean'][$variables['block']->delta]['#entity']->field_block_color[LANGUAGE_NONE][0]['value']);
}
}
}