You are here

public function TaxonomyIndexTid::buildOptionsForm in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/taxonomy/src/Plugin/views/field/TaxonomyIndexTid.php \Drupal\taxonomy\Plugin\views\field\TaxonomyIndexTid::buildOptionsForm()

Provide "link to term" option.

Overrides PrerenderList::buildOptionsForm

File

core/modules/taxonomy/src/Plugin/views/field/TaxonomyIndexTid.php, line 85

Class

TaxonomyIndexTid
Field handler to display all taxonomy terms of a node.

Namespace

Drupal\taxonomy\Plugin\views\field

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  $form['link_to_taxonomy'] = [
    '#title' => $this
      ->t('Link this field to its term page'),
    '#type' => 'checkbox',
    '#default_value' => !empty($this->options['link_to_taxonomy']),
  ];
  $form['limit'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Limit terms by vocabulary'),
    '#default_value' => $this->options['limit'],
  ];
  $options = [];
  $vocabularies = $this->vocabularyStorage
    ->loadMultiple();
  foreach ($vocabularies as $voc) {
    $options[$voc
      ->id()] = $voc
      ->label();
  }
  $form['vids'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Vocabularies'),
    '#options' => $options,
    '#default_value' => $this->options['vids'],
    '#states' => [
      'visible' => [
        ':input[name="options[limit]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  parent::buildOptionsForm($form, $form_state);
}