You are here

protected function TranslationTargetLanguageFilter::valueForm in Translation Views 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/TranslationTargetLanguageFilter.php, line 184

Class

TranslationTargetLanguageFilter
Provides filtering by translation target language.

Namespace

Drupal\translation_views\Plugin\views\filter

Code

protected function valueForm(&$form, FormStateInterface $form_state) {
  parent::valueForm($form, $form_state);
  if (!empty($this->options['exposed'])) {
    $language_options = $this
      ->buildLanguageOptions();
    $identifier = $this->options['expose']['identifier'];
    $user_input = $form_state
      ->getUserInput();
    $target_langcode = isset($user_input[$identifier]) ? $user_input[$identifier] : $this->value;
    $valid_langcode = $this
      ->getValidLangcode($target_langcode, $language_options);
    $this
      ->setExposedValue($identifier, $valid_langcode, $form_state);
  }
  $this->always_required = TRUE;
  $form['value'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Default target language'),
    '#options' => $this
      ->buildLanguageOptions(),
    '#multiple' => FALSE,
    '#required' => TRUE,
    '#default_value' => $this->value,
  ];
  $form['expose']['identifier'] = [
    '#type' => 'hidden',
    '#value' => static::$targetExposedKey,
  ];
}