You are here

function ds_extras_ds_field_settings_alter in Display Suite 7

Same name and namespace in other branches
  1. 7.2 modules/ds_extras/ds_extras.module \ds_extras_ds_field_settings_alter()

Implements hook_ds_field_settings_alter().

File

modules/ds_extras/ds_extras.admin.inc, line 542
Display Suite Extras administrative functions.

Code

function ds_extras_ds_field_settings_alter(&$field_settings, $form, &$form_state) {
  $fields = $form_state['values']['fields'];
  $default_field_function = variable_get('ft-default', 'theme_field');
  $wrappers = array(
    'ow' => t('Wrapper'),
    'fis' => t('Field items'),
    'fi' => t('Field item'),
  );
  foreach ($fields as $key => $field) {

    // Make sure we need to save anything for this field.
    if (_ds_field_valid($key, $field, $form_state)) {
      continue;
    }

    // Get the values.
    $values = isset($fields[$key]['format']['ft']) ? $fields[$key]['format']['ft'] : array();
    if (empty($values)) {
      continue;
    }

    // Theme output function.
    $function = $values['function'];
    if ($function != $default_field_function) {
      $field_settings[$key]['ft']['func'] = $function;
    }

    // Field styles.
    if ($function != 'theme_ds_field_expert' && $function != 'theme_ds_field_reset') {
      $classes = implode(' ', $values['styles']);
      if (!empty($classes)) {
        $field_settings[$key]['ft']['styles'] = $classes;
      }
    }

    // Label.
    if (isset($fields[$key]['label']) && $fields[$key]['label'] != 'hidden') {
      if (!empty($values['lb'])) {
        $field_settings[$key]['ft']['lb'] = $values['lb'];
      }
      if (!empty($values['lb-el']) && $function == 'theme_ds_field_expert') {
        $field_settings[$key]['ft']['lb-el'] = check_plain($values['lb-el']);
      }
      if (!empty($values['lb-cl']) && $function == 'theme_ds_field_expert') {
        $field_settings[$key]['ft']['lb-cl'] = check_plain($values['lb-cl']);
      }
      if (!empty($values['lb-col'])) {
        $field_settings[$key]['ft']['lb-col'] = TRUE;
      }
    }

    // Custom field configuration.
    if ($function == 'theme_ds_field_expert') {
      foreach ($wrappers as $wrapper_key => $title) {
        if ($values[$wrapper_key]) {

          // Enable.
          $field_settings[$key]['ft'][$wrapper_key] = TRUE;

          // Element.
          $field_settings[$key]['ft'][$wrapper_key . '-el'] = !empty($values[$wrapper_key . '-el']) ? check_plain($values[$wrapper_key . '-el']) : 'div';

          // Classess.
          $field_settings[$key]['ft'][$wrapper_key . '-cl'] = !empty($values[$wrapper_key . '-cl']) ? check_plain($values[$wrapper_key . '-cl']) : '';
        }
      }
    }
  }
}