You are here

public function Field::buildOptionsForm in Views (for Drupal 7) 8.3

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

Overrides FieldPluginBase::buildOptionsForm

File

lib/Views/field/Plugin/views/field/Field.php, line 325
Definition of Views\field\Plugin\views\field\Field.

Class

Field
A field that displays fieldapi fields.

Namespace

Views\field\Plugin\views\field

Code

public function buildOptionsForm(&$form, &$form_state) {
  parent::buildOptionsForm($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().
  $this->instance = $this
    ->fakeFieldInstance($format, $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;
}