You are here

public function ViewsFieldsOnOffForm::buildOptionsForm in Views Fields On/Off 8

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

Overrides FieldPluginBase::buildOptionsForm

File

src/Plugin/views/field/ViewsFieldsOnOffForm.php, line 77

Class

ViewsFieldsOnOffForm
Provides a handler that adds the form for Fields On/Off.

Namespace

Drupal\views_fields_on_off\Plugin\views\field

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  $all_fields = $this->displayHandler
    ->getFieldLabels();

  // Remove any field that have been excluded from the display from the list.
  foreach ($all_fields as $key => $field) {
    $exclude = $this->view->display_handler->handlers['field'][$key]->options['exclude'];
    if ($exclude) {
      unset($all_fields[$key]);
    }
  }

  // Offer to include only those fields that follow this one.
  $field_options = array_slice($all_fields, 0, array_search($this->options['id'], array_keys($all_fields)));
  $form['fields'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Fields'),
    '#description' => $this
      ->t('Fields to be turned on and off.'),
    '#options' => $field_options,
    '#default_value' => $this->options['fields'],
  ];
  $form['exposed_select_type'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Exposed Selection Field Type'),
    '#description' => t('Fields to be turned on and off.'),
    '#options' => [
      'checkboxes' => $this
        ->t('Checkboxes'),
      'radios' => $this
        ->t('Radios'),
      'select' => $this
        ->t('Single select'),
      'multi_select' => $this
        ->t('Multiple select'),
    ],
    '#default_value' => $this->options['exposed_select_type'],
  ];
}