protected function ShsChosenTaxonomyIndexTid::valueForm in Simple hierarchical select 8
Same name and namespace in other branches
- 2.0.x modules/shs_chosen/src/Plugin/views/filter/ShsChosenTaxonomyIndexTid.php \Drupal\shs_chosen\Plugin\views\filter\ShsChosenTaxonomyIndexTid::valueForm()
Options form subform for setting options.
This should be overridden by all child classes and it must define $form['value']
Overrides ShsTaxonomyIndexTid::valueForm
See also
buildOptionsForm()
File
- modules/
shs_chosen/ src/ Plugin/ views/ filter/ ShsChosenTaxonomyIndexTid.php, line 127
Class
- ShsChosenTaxonomyIndexTid
- Filter by term id using "Simple hierarchical select: chosen" widgets.
Namespace
Drupal\shs_chosen\Plugin\views\filterCode
protected function valueForm(&$form, FormStateInterface $form_state) {
$type = $this->options['type'];
if ('shs_chosen' !== $type) {
// Let the parent class generate the base form.
parent::valueForm($form, $form_state);
return;
}
// Small hack to process the element as shs element.
$this->options['type'] = 'shs';
parent::valueForm($form, $form_state);
// Reset type.
$this->options['type'] = $type;
if (empty($this->options['expose']['chosen_override'])) {
// No need to modify the display of the form element.
return;
}
if (empty($form['value']['#shs'])) {
// Something went wrong.
return;
}
$chosen_defaults = $this
->defaultChosenSettings();
// Get overridden chosen settings.
$chosen_overrides = array_intersect_key($this->options['expose'], $chosen_defaults);
$chosen_conf = $chosen_overrides + \Drupal::config('chosen.settings')
->get();
$settings_shs = $form['value']['#shs'];
$settings_shs['chosen_override'] = TRUE;
$settings_shs['chosen_settings'] = $chosen_conf;
if (empty($settings_shs['display'])) {
$settings_shs['display'] = [];
}
$settings_shs['display']['chosen'] = [
'selector' => 'select.shs-select',
'minimum_single' => 0,
'minimum_multiple' => 0,
'minimum_width' => (int) $chosen_conf['minimum_width'],
'options' => [
'disable_search' => (bool) $chosen_conf['disable_search'],
'disable_search_threshold' => (int) $chosen_conf['disable_search_threshold'],
'search_contains' => (bool) $chosen_conf['search_contains'],
'placeholder_text_multiple' => $chosen_conf['placeholder_text_multiple'],
'placeholder_text_single' => $chosen_conf['placeholder_text_single'],
'no_results_text' => $chosen_conf['no_results_text'],
'inherit_select_classes' => TRUE,
],
];
$context = [
'settings' => $settings_shs,
'object' => $this,
];
$field_name = isset($this->definition['field_name']) ? $this->definition['field_name'] : $this->realField;
$settings_shs['classes'] = shs_get_class_definitions($field_name, $context);
$form['value']['#attached']['drupalSettings']['shs'][$form['value']['#attributes']['data-shs-selector']] = $form['value']['#shs'] = $settings_shs;
$form['value']['#attached']['library'][] = 'shs_chosen/shs_chosen.form';
}