You are here

function ds_extras_field_template_settings_form in Display Suite 7.2

Field template settings form

2 calls to ds_extras_field_template_settings_form()
ds_field_settings_form in includes/ds.field_ui.inc
Creates a form for Display Suite fields. .
_ds_field_ui_core_fields in includes/ds.field_ui.inc
Alter the core field on the the Field UI form.

File

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

Code

function ds_extras_field_template_settings_form(array &$form, array &$form_state, array $context) {
  $functions = module_invoke_all('ds_field_theme_functions_info');
  $default_field_function = variable_get('ft-default', 'theme_field');
  $key = $context['instance']['field_name'];
  $field_settings = isset($form_state['formatter_settings'][$key]) ? $form_state['formatter_settings'][$key]['ft'] : array();
  $field_function = isset($field_settings['func']) ? $field_settings['func'] : $default_field_function;
  $field_classes = _ds_classes('ds_classes_fields');
  $form['ft'] = array(
    '#weight' => 20,
  );

  // Functions.
  $form['ft']['func'] = array(
    '#title' => t('Choose a Field Template'),
    '#type' => 'select',
    '#options' => $functions,
    '#default_value' => $field_function,
    '#attributes' => array(
      'class' => array(
        'ds-extras-field-template',
      ),
    ),
  );

  // Field classes.
  if (!empty($field_classes)) {
    $field_classes_select = array(
      '#type' => 'select',
      '#multiple' => TRUE,
      '#options' => $field_classes,
      '#title' => t('Choose additional CSS classes for the field'),
      '#default_value' => isset($field_settings['classes']) ? explode(' ', $field_settings['classes']) : array(),
      '#prefix' => '<div class="field-classes">',
      '#suffix' => '</div>',
    );
    $form['ft']['classes'] = $field_classes_select;
  }
  else {
    $form['ft']['classes'] = array(
      '#type' => 'value',
      '#value' => array(
        '',
      ),
    );
  }

  // Add prefix
  $form['ft']['prefix'] = array(
    '#type' => 'textfield',
    '#title' => t('Prefix'),
    '#size' => '100',
    '#description' => t('You can enter any html in here.'),
    '#default_value' => isset($field_settings['prefix']) ? $field_settings['prefix'] : '',
    '#prefix' => '<div class="field-prefix">',
    '#suffix' => '</div>',
  );

  // Wrappers and label.
  $wrappers = array(
    'lb' => array(
      'title' => t('Label'),
    ),
    'lbw' => array(
      'title' => t('Label wrapper'),
    ),
    'ow' => array(
      'title' => t('Outer wrapper'),
    ),
    'fis' => array(
      'title' => t('Field items'),
    ),
    'fi' => array(
      'title' => t('Field item'),
    ),
  );
  foreach ($wrappers as $wrapper_key => $value) {
    $classes = array(
      'field-name-' . strtr($key, '_', '-'),
    );
    $form['ft'][$wrapper_key] = array(
      '#type' => 'checkbox',
      '#title' => $value['title'],
      '#prefix' => '<div class="ft-group ' . $wrapper_key . '">',
      '#default_value' => isset($field_settings[$wrapper_key]) ? $field_settings[$wrapper_key] : FALSE,
    );
    $form['ft'][$wrapper_key . '-el'] = array(
      '#type' => 'textfield',
      '#title' => t('Element'),
      '#size' => '10',
      '#description' => t('E.g. div, span, h2 etc.'),
      '#default_value' => isset($field_settings[$wrapper_key . '-el']) ? $field_settings[$wrapper_key . '-el'] : '',
      '#states' => array(
        'visible' => array(
          ':input[name$="[ft][' . $wrapper_key . ']"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $form['ft'][$wrapper_key . '-cl'] = array(
      '#type' => 'textfield',
      '#title' => t('Classes'),
      '#size' => '10',
      '#default_value' => isset($field_settings[$wrapper_key . '-cl']) ? $field_settings[$wrapper_key . '-cl'] : '',
      '#description' => t('E.g.') . ' ' . implode(', ', $classes),
      '#states' => array(
        'visible' => array(
          ':input[name$="[ft][' . $wrapper_key . ']"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $form['ft'][$wrapper_key . '-at'] = array(
      '#type' => 'textfield',
      '#title' => t('Attributes'),
      '#size' => '20',
      '#default_value' => isset($field_settings[$wrapper_key . '-at']) ? $field_settings[$wrapper_key . '-at'] : '',
      '#description' => t('E.g. name="anchor"'),
      '#states' => array(
        'visible' => array(
          ':input[name$="[ft][' . $wrapper_key . ']"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );

    // Hide colon.
    if ($wrapper_key == 'lb') {
      $form['ft']['lb-col'] = array(
        '#type' => 'checkbox',
        '#title' => t('Hide label colon'),
        '#default_value' => isset($field_settings['lb-col']) ? $field_settings['lb-col'] : FALSE,
        '#attributes' => array(
          'class' => array(
            'colon-checkbox',
          ),
        ),
      );
    }
    if ($wrapper_key == 'fi') {
      $form['ft']['fi-odd-even'] = array(
        '#type' => 'checkbox',
        '#title' => t('Add odd/even classes'),
        '#default_value' => isset($field_settings['fi-odd-even']) ? $field_settings['fi-odd-even'] : FALSE,
        '#states' => array(
          'visible' => array(
            ':input[name$="[ft][' . $wrapper_key . ']"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
      $form['ft']['fi-first-last'] = array(
        '#type' => 'checkbox',
        '#title' => t('Add first/last classes'),
        '#default_value' => isset($field_settings['fi-first-last']) ? $field_settings['fi-first-last'] : FALSE,
        '#states' => array(
          'visible' => array(
            ':input[name$="[ft][' . $wrapper_key . ']"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
    }
    if ($wrapper_key != 'lbw') {
      $form['ft'][$wrapper_key . '-def-at'] = array(
        '#type' => 'checkbox',
        '#title' => t('Add default attributes'),
        '#default_value' => isset($field_settings[$wrapper_key . '-def-at']) ? $field_settings[$wrapper_key . '-def-at'] : FALSE,
        '#suffix' => $wrapper_key == 'ow' ? '' : '</div>',
        '#states' => array(
          'visible' => array(
            ':input[name$="[ft][' . $wrapper_key . ']"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
    }
    else {
      $form['ft'][$wrapper_key . '-def-at'] = array(
        '#markup' => '</div><div class="clearfix"></div>',
      );
    }

    // Default classes for outer wrapper.
    if ($wrapper_key == 'ow') {
      $form['ft'][$wrapper_key . '-def-cl'] = array(
        '#type' => 'checkbox',
        '#title' => t('Add default classes'),
        '#default_value' => isset($field_settings[$wrapper_key . '-def-cl']) ? $field_settings[$wrapper_key . '-def-cl'] : FALSE,
        '#suffix' => '</div>',
        '#states' => array(
          'visible' => array(
            ':input[name$="[ft][' . $wrapper_key . ']"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
    }
  }

  // Add suffix
  $form['ft']['suffix'] = array(
    '#type' => 'textfield',
    '#title' => t('Suffix'),
    '#size' => '100',
    '#description' => t('You can enter any html in here.'),
    '#default_value' => isset($field_settings['suffix']) ? $field_settings['suffix'] : '',
    '#prefix' => '<div class="field-prefix">',
    '#suffix' => '</div>',
  );

  // Another label needs some other stuff.
  unset($form['ft']['lb']['#description']);
  $form['ft']['lb']['#type'] = 'textfield';
  $form['ft']['lb']['#size'] = '10';
  $form['ft']['lb']['#attributes'] = array(
    'class' => array(
      'label-change',
    ),
  );
  $form['ft']['lb']['#default_value'] = isset($field_settings['lb']) ? $field_settings['lb'] : '';

  // Let other modules make modifications to the settings form as needed.
  drupal_alter('ds_field_theme_functions_settings_form_alter', $form, $field_settings);
}