You are here

public function SelectOtherFilter::valueSubmit in CCK Select Other 8

Perform any necessary changes to the form values prior to storage. There is no need for this function to actually store the data.

Overrides InOperator::valueSubmit

File

src/Plugin/views/filter/SelectOtherFilter.php, line 108

Class

SelectOtherFilter
Select other filter handler.

Namespace

Drupal\cck_select_other\Plugin\views\filter

Code

public function valueSubmit($form, FormStateInterface $form_state) {
  parent::valueSubmit($form, $form_state);
  if (is_array($form['value']['select_other_list']['#value'])) {
    $values = [];
    foreach ($form['value']['select_other_list']['#value'] as $key => $value) {
      if ($key === 'other') {
        $values[] = $form['value']['select_other_text_input']['#value'];
      }
      else {
        $values[] = $value;
      }
    }
  }
  else {
    if ($form['value']['select_other_list']['#value'] === 'other') {
      $values = $form['value']['select_other_text_input']['#value'];
    }
    else {
      $values = $form['value']['select_other_list']['#value'];
    }
  }

  // Set the form state based on whether or not the form is exposed to the
  // user because the form element #parents arbitrarily change.
  $parents = $form_state
    ->get('exposed') ? [
    $this->options['expose']['identifier'],
  ] : [
    'options',
    'value',
  ];
  $form_state
    ->setValueForElement([
    '#parents' => $parents,
  ], $values);
}