public function TaxonomyIndexMachineName::buildExtraOptionsForm in Taxonomy Machine Name 8
Provide a form for setting options.
Overrides HandlerBase::buildExtraOptionsForm
File
- src/
Plugin/ views/ filter/ TaxonomyIndexMachineName.php, line 121
Class
- TaxonomyIndexMachineName
- Filter by term id.
Namespace
Drupal\taxonomy_machine_name\Plugin\views\filterCode
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',
],
],
],
];
}