public function SelectOtherFilter::valueForm in CCK Select Other 8
Options form subform for setting options.
This should be overridden by all child classes and it must define $form['value']
Overrides ManyToOne::valueForm
See also
buildOptionsForm()
File
- src/
Plugin/ views/ filter/ SelectOtherFilter.php, line 57
Class
- SelectOtherFilter
- Select other filter handler.
Namespace
Drupal\cck_select_other\Plugin\views\filterCode
public function valueForm(&$form, FormStateInterface $form_state) {
parent::valueForm($form, $form_state);
$old_form = $form['value'];
$form['value'] = [
'#tree' => TRUE,
'#type' => 'container',
'#attributes' => [
'class' => [
'form-select-other-wrapper',
'cck-select-other-wrapper',
],
],
'select_other_list' => $old_form,
'select_other_text_input' => [
'#type' => 'textfield',
'#title' => $this
->t('Provide other option'),
'#size' => 30,
'#attributes' => [
'class' => [
'form-text',
'form-select-other-text-input',
],
],
],
];
$form['value']['select_other_list']['#attributes']['class'][] = 'form-select-other-list';
if ($form_state
->get('exposed')) {
// Set the parents on the exposed element to a long string instead of an
// array like should be able to do in a normal form array. DrupalWTF.
if ($identifier = $this->options['expose']['identifier']) {
$form['value']['select_other_list']['#parents'] = [
$identifier . '_select_other_list',
];
$form['value']['select_other_text_input']['#parents'] = [
$identifier . '_select_other_text_input',
];
}
// Set multiple.
$form['value']['select_other_list']['#multiple'] = $this->options['expose']['multiple'];
// Attach JavaScript.
$element_class = 'form-item-' . str_replace('_', '-', $identifier) . '-select-other-list';
$form['value']['#attached'] = [
'library' => [
'cck_select_other/widget',
],
'drupalSettings' => [
'CCKSelectOther' => [
$identifier => [
$element_class,
],
],
],
];
}
}