You are here

public function views_handler_field_field::options_form in Views (for Drupal 7) 7.3

Default options form provides the label widget that all fields should have.

Overrides views_handler_field::options_form

File

modules/field/views_handler_field_field.inc, line 417
Definition of views_handler_field_field.

Class

views_handler_field_field
A field that displays fieldapi fields.

Code

public function options_form(&$form, &$form_state) {
  parent::options_form($form, $form_state);
  $field = $this->field_info;
  $formatters = _field_view_formatter_options($field['type']);
  $column_names = array_keys($field['columns']);

  // If this is a multiple value field, add its options.
  if ($this->multiple) {
    $this
      ->multiple_options_form($form, $form_state);
  }

  // No need to ask the user anything if the field has only one column.
  if (count($field['columns']) == 1) {
    $form['click_sort_column'] = array(
      '#type' => 'value',
      '#value' => isset($column_names[0]) ? $column_names[0] : '',
    );
  }
  else {
    $form['click_sort_column'] = array(
      '#type' => 'select',
      '#title' => t('Column used for click sorting'),
      '#options' => drupal_map_assoc($column_names),
      '#default_value' => $this->options['click_sort_column'],
      '#description' => t('Used by Style: Table to determine the actual column to click sort the field on. The default is usually fine.'),
      '#fieldset' => 'more',
    );
  }
  $form['type'] = array(
    '#type' => 'select',
    '#title' => t('Formatter'),
    '#options' => $formatters,
    '#default_value' => $this->options['type'],
    '#ajax' => array(
      'path' => views_ui_build_form_url($form_state),
    ),
    '#submit' => array(
      'views_ui_config_item_form_submit_temporary',
    ),
    '#executes_submit_callback' => TRUE,
  );
  $form['field_api_classes'] = array(
    '#title' => t('Use field template'),
    '#type' => 'checkbox',
    '#default_value' => $this->options['field_api_classes'],
    '#description' => t('If checked, field api classes will be added using field.tpl.php (or equivalent). This is not recommended unless your CSS depends upon these classes. If not checked, template will not be used.'),
    '#fieldset' => 'style_settings',
    '#weight' => 20,
  );
  if ($this->multiple) {
    $form['field_api_classes']['#description'] .= ' ' . t('Checking this option will cause the group Display Type and Separator values to be ignored.');
  }

  // Get the currently selected formatter.
  $format = $this->options['type'];
  $formatter = field_info_formatter_types($format);
  $settings = $this->options['settings'] + field_info_formatter_settings($format);

  // Provide an instance array for hook_field_formatter_settings_form().
  ctools_include('fields');
  $this->instance = ctools_fields_fake_field_instance($this->definition['field_name'], '_custom', $formatter, $settings);

  // Store the settings in a '_custom' view mode.
  $this->instance['display']['_custom'] = array(
    'type' => $format,
    'settings' => $settings,
  );

  // Get the settings form.
  $settings_form = array(
    '#value' => array(),
  );
  $function = $formatter['module'] . '_field_formatter_settings_form';
  if (function_exists($function)) {
    $settings_form = $function($field, $this->instance, '_custom', $form, $form_state);
  }
  $form['settings'] = $settings_form;
}