Same name and namespace in other branches
  1. 8.9.x core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php \Drupal\taxonomy\Plugin\views\filter\TaxonomyIndexTid::buildExtraOptionsForm()
  2. 9 core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php \Drupal\taxonomy\Plugin\views\filter\TaxonomyIndexTid::buildExtraOptionsForm()
1 call to TaxonomyIndexTid::buildExtraOptionsForm()
TaxonomyIndexTidDepth::buildExtraOptionsForm in core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTidDepth.php
1 method overrides TaxonomyIndexTid::buildExtraOptionsForm()
TaxonomyIndexTidDepth::buildExtraOptionsForm in core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTidDepth.php

File

core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php, line 124

Class

TaxonomyIndexTid

Namespace

Drupal\taxonomy\Plugin\views\filter

Code

public function buildExtraOptionsForm(&$form, FormStateInterface $form_state) {
  $vocabularies = $this->vocabularyStorage
    ->loadMultiple();
  $options = [];
  foreach ($vocabularies as $voc) {
    $options[$voc
      ->id()] = $voc
      ->label();
  }
  if ($this->options['limit']) {

    // We only do this when the form is displayed.
    if (empty($this->options['vid'])) {
      $first_vocabulary = reset($vocabularies);
      $this->options['vid'] = $first_vocabulary
        ->id();
    }
    if (empty($this->definition['vocabulary'])) {
      $form['vid'] = [
        '#type' => 'radios',
        '#title' => $this
          ->t('Vocabulary'),
        '#options' => $options,
        '#description' => $this
          ->t('Select which vocabulary to show terms for in the regular options.'),
        '#default_value' => $this->options['vid'],
      ];
    }
  }
  $form['type'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Selection type'),
    '#options' => [
      'select' => $this
        ->t('Dropdown'),
      'textfield' => $this
        ->t('Autocomplete'),
    ],
    '#default_value' => $this->options['type'],
  ];
  $form['hierarchy'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show hierarchy in dropdown'),
    '#default_value' => !empty($this->options['hierarchy']),
    '#states' => [
      'visible' => [
        ':input[name="options[type]"]' => [
          'value' => 'select',
        ],
      ],
    ],
  ];
}