You are here

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

Render our chunk of the exposed handler form when selecting

Overrides HandlerBase::buildExposedForm

File

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

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 buildExposedForm(&$form, FormStateInterface $form_state) {
  $field_id = $this->options['id'];
  $label = $this->options['label'];
  $selected_options = $this->options['fields'];
  $all_fields = $this->displayHandler
    ->getFieldLabels();
  $options = array_filter($all_fields, function ($key) use ($selected_options) {
    return in_array($key, $selected_options, TRUE);
  }, ARRAY_FILTER_USE_KEY);
  $form[$field_id] = [
    '#type' => $this->options['exposed_select_type'],
    '#title' => $this
      ->t('@value', [
      '@value' => $label,
    ]),
    '#description' => $this
      ->t('Select the fields you want to display.'),
    '#options' => $options,
  ];
  if ($this->options['exposed_select_type'] == 'multi_select') {
    $form[$field_id]['#type'] = 'select';
    $form[$field_id]['#multiple'] = TRUE;
  }
  $form['fields_on_off_hidden_submitted'] = [
    '#type' => 'hidden',
    '#default_value' => 1,
  ];
}