You are here

protected function ContentLanguageFallbackLimitedFilter::valueForm in Language Hierarchy 8

Same name and namespace in other branches
  1. 2.x src/Plugin/views/filter/ContentLanguageFallbackLimitedFilter.php \Drupal\language_hierarchy\Plugin\views\filter\ContentLanguageFallbackLimitedFilter::valueForm()

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/ContentLanguageFallbackLimitedFilter.php, line 121

Class

ContentLanguageFallbackLimitedFilter
Filters to the most relevant translation for the current content language.

Namespace

Drupal\language_hierarchy\Plugin\views\filter

Code

protected function valueForm(&$form, FormStateInterface $form_state) {
  $exposed = $form_state
    ->get('exposed');
  $form['value'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show only the most specific translation for the content language selected for a page.'),
    '#default_value' => $this->value,
  ];

  // This filter only supports the Sql backend.
  $query_plugin = $this->displayHandler
    ->getPlugin('query');
  if (!$query_plugin instanceof Sql) {
    $form['value']['#disabled'] = TRUE;
    $form['value']['#default_value'] = '';
    $form['value']['#description'] = $this
      ->t('This option only supports the <em>Sql</em> query backend.');
  }

  // @see \Drupal\views\Plugin\views\filter\BooleanOperator::valueForm()
  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);
    }
  }
}