how to add the value of a (list text) field as a class I have a CT on which I have a field called monetary-type which is of type List (text) and its "Allowed values list" is:

EUR|Euros
USD|Dollars
GBP|Pounds


When this field is rendered from a view (FORMAT: Show: Fields) it's being rendered as:

&lt;span class="views-field views-field-field-monetary-type"&gt;
  &lt;span class="field-content"&gt;Dollars&lt;/span&gt;
&lt;/span&gt;


When rendered from a node view it shows as:

&lt;div class="field field-name-field-monetary-type field-type-list-text field-label-above field-wrapper"&gt;
  Dollars
&lt;/div&gt;


For both those 2 cases I'd like to also have a class with the selected value, in this case value-USD, appended into the classnames of the wrapper.

What is the easiest (non intrusive) way I can achieve this? Ideally without having to touch existing views or node displays.

I use https://www.drupal.org/project/zurb_foundation if it matters.
For view field, please implements template_preprocess_views_view_fields()

Reference: https://www.drupal.org/node/1407442#comment-6509858

Code Example

// assume the field name is 'field_text' and
// view name is 'text and view display id is 'page'
function mymodule_preprocess_views_view_fields(&amp;$variables) {
  $view = $variables['view'];
  if ($view-&gt;name == 'test' &amp;&amp; $view-&gt;current_display == 'page') {
    foreach ($variables['fields'] as $id =&gt; $object) {
      if ($id == 'field_text') {
        $field_output = $view-&gt;style_plugin-&gt;get_field($view-&gt;row_index, $id);

        if (!empty($field_output)) {
          if ($object-&gt;element_type) {
            $class = '';
            if ($object-&gt;handler-&gt;options['element_default_classes']) {
              $class = 'field-content';
            }

            if ($classes = $object-&gt;handler-&gt;element_classes($view-&gt;row_index)) {
              if ($class) {
                $class .= ' ';
              }
              $class .=  $classes;
            }

            $class .=  ' ' . drupal_html_class("value-$field_output");

            $pre = '&lt;' . $object-&gt;element_type;
            if ($class) {
              $pre .= ' class="' . $class . '"';
            }
            $field_output = $pre . '&gt;' . $field_output . '&lt;/' . $object-&gt;element_type . '&gt;';
          }
        }
        $variables['fields'][$id]-&gt;content = $field_output;
      }
    }
  }
}


For node field, please implements template_preprocess_field()

Code Example

// Assume the field name is 'field_text'
function mytheme_preprocess_field(&amp;$variables) {
  $element = &amp;$variables['element'];
  if ($element['#field_name'] === 'field_text') {
    $value = $element['#items'][0]['value'];
    $variables['classes_array'][] = drupal_html_class("value-$value");
  }
}


Note 1: I would recommend using lower case for class name.
Note 2: view_field_name is different from node_field_name