You are here

function template_preprocess_field__ds_field_expert in Display Suite 8.2

Same name and namespace in other branches
  1. 8.4 ds.module \template_preprocess_field__ds_field_expert()
  2. 8.3 ds.module \template_preprocess_field__ds_field_expert()

Implements template_preprocess_ds_field_expert().

File

./ds.module, line 899
Display Suite core functions.

Code

function template_preprocess_field__ds_field_expert(&$variables) {
  $variables['settings'] = isset($variables['ds-config']['settings']) ? $variables['ds-config']['settings'] : [];
  $vars = array(
    'lbw' => 'label_attributes',
    'ow' => 'wrapper_attributes',
    'fis' => 'field_wrapper_attributes',
    'fi' => 'field_item_wrapper_attributes',
  );
  foreach ($vars as $key => $variable_name) {
    $var_attributes = array();

    // Add classes.
    if (!empty($variables['settings'][$key . '-cl'])) {
      $var_attributes['class'] = explode(' ', $variables['settings'][$key . '-cl']);
    }

    // Add attributes.
    if (!empty($variables['settings'][$key . '-at'])) {
      $attributes = explode(' ', $variables['settings'][$key . '-at']);
      foreach ($attributes as $key => $attribute) {
        if (strpos($attribute, '=') !== FALSE) {
          $attribute_parts = explode('=', $attribute);
          $var_attributes[$attribute_parts[0]] = trim($attribute_parts[1], '\\"');
        }
      }
    }
    $variables[$variable_name] = new DsAttribute($var_attributes);
  }

  // In order to allow HTML we need to filter XSS the output of the
  // prefix/suffix.
  $variables['settings']['prefix'] = XSS::filterAdmin($variables['settings']['prefix']);
  $variables['settings']['suffix'] = XSS::filterAdmin($variables['settings']['suffix']);
}