You are here

function fences_preprocess_field in Fences 8.2

Same name and namespace in other branches
  1. 7.2 fences.module \fences_preprocess_field()
  2. 7 fences.module \fences_preprocess_field()

Implememts hook_preprocess_field().

File

./fences.module, line 91
Alter wrapping markup of fields.

Code

function fences_preprocess_field(&$vars) {

  // Default to showing all markup.
  $vars['display_label_tag'] = TRUE;
  $vars['display_field_tag'] = TRUE;
  $vars['display_item_tag'] = TRUE;
  if (isset($vars['element']['#third_party_settings']['fences'])) {
    $fences_config = $vars['element']['#third_party_settings']['fences'];
    $vars['display_label_tag'] = $fences_config['fences_label_tag'] !== TagManagerInterface::NO_MARKUP_VALUE;
    $vars['display_field_tag'] = $fences_config['fences_field_tag'] !== TagManagerInterface::NO_MARKUP_VALUE;
    $vars['display_item_tag'] = $fences_config['fences_field_item_tag'] !== TagManagerInterface::NO_MARKUP_VALUE;
    $vars['label_tag'] = $fences_config['fences_label_tag'];
    $vars['field_tag'] = $fences_config['fences_field_tag'];
    $vars['field_item_tag'] = $fences_config['fences_field_item_tag'];
    $vars['attributes']['class'][] = $fences_config['fences_field_classes'];
    $vars['title_attributes']['class'][] = $fences_config['fences_label_classes'];
    if (!empty($fences_config['fences_field_item_classes'])) {
      foreach ($vars['items'] as $field_item) {
        $field_item['attributes']
          ->addClass($fences_config['fences_field_item_classes']);
      }
    }
  }
}