You are here

protected function EmailVerification::valueForm in User email verification 8

Options form subform for setting options.

This should be overridden by all child classes and it must define $form['value']

Overrides FilterPluginBase::valueForm

See also

buildOptionsForm()

File

src/Plugin/views/filter/EmailVerification.php, line 166

Class

EmailVerification
Simple filter to handle matching of boolean values

Namespace

Drupal\user_email_verification\Plugin\views\filter

Code

protected function valueForm(&$form, FormStateInterface $form_state) {
  if (empty($this->valueOptions)) {

    // Initialize the array of possible values for this filter.
    $this
      ->getValueOptions();
  }
  if ($exposed = $form_state
    ->get('exposed')) {

    // Exposed filter: use a select box to save space.
    $filter_form_type = 'select';
  }
  else {

    // Configuring a filter: use radios for clarity.
    $filter_form_type = 'radios';
  }
  $form['value'] = [
    '#type' => $filter_form_type,
    '#title' => $this->value_value,
    '#options' => $this->valueOptions,
    '#default_value' => $this->value,
  ];
  if (!empty($this->options['exposed'])) {
    $identifier = $this->options['expose']['identifier'];
    $user_input = $form_state
      ->getUserInput();
    if ($exposed && !isset($user_input[$identifier])) {
      $user_input[$identifier] = $this->value;
      $form_state
        ->setUserInput($user_input);
    }

    // If we're configuring an exposed filter, add an - Any - option.
    if (!$exposed || empty($this->options['expose']['required'])) {
      $form['value']['#options'] = [
        'All' => $this
          ->t('- Any -'),
      ] + $form['value']['#options'];
    }
  }
}