public function OptionsShsChosenWidget::settingsForm in Simple hierarchical select 2.0.x
Same name and namespace in other branches
- 8 modules/shs_chosen/src/Plugin/Field/FieldWidget/OptionsShsChosenWidget.php \Drupal\shs_chosen\Plugin\Field\FieldWidget\OptionsShsChosenWidget::settingsForm()
Returns a form to configure settings for the widget.
Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the widget. The field_ui module takes care of handling submitted form values.
Parameters
array $form: The form where the settings form is being included in.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form definition for the widget settings.
Overrides OptionsShsWidget::settingsForm
File
- modules/
shs_chosen/ src/ Plugin/ Field/ FieldWidget/ OptionsShsChosenWidget.php, line 44
Class
- OptionsShsChosenWidget
- Plugin implementation of the 'options_shs_chosen' widget.
Namespace
Drupal\shs_chosen\Plugin\Field\FieldWidgetCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$field_name = $this->fieldDefinition
->getName();
$element = parent::settingsForm($form, $form_state);
// Add custom settings.
$element['chosen_override'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Custom chosen settings'),
'#default_value' => $this
->getSetting('chosen_override'),
'#description' => $this
->t('Override <a href=":url">global settings</a> made for chosen.', [
':url' => Url::fromRoute('chosen.admin')
->toString(),
]),
];
$chosen_settings = $this
->getSetting('chosen_settings');
$element['chosen_settings'] = [
'#type' => 'details',
'#title' => $this
->t('Chosen overrides'),
'#open' => TRUE,
'#states' => [
'invisible' => [
'input[name="fields[' . $field_name . '][settings_edit_form][settings][chosen_override]"]' => [
'checked' => FALSE,
],
],
],
];
$element['chosen_settings']['disable_search'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Disable search box'),
'#default_value' => $chosen_settings['disable_search'],
];
$element['chosen_settings']['search_contains'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Search also in the middle of words'),
'#default_value' => $chosen_settings['search_contains'],
];
$element['chosen_settings']['placeholder_text_multiple'] = [
'#type' => 'textfield',
'#title' => $this
->t('Placeholder text of multiple selects'),
'#default_value' => $chosen_settings['placeholder_text_multiple'],
];
$element['chosen_settings']['placeholder_text_single'] = [
'#type' => 'textfield',
'#title' => $this
->t('Placeholder text of single selects'),
'#default_value' => $chosen_settings['placeholder_text_single'],
];
$element['chosen_settings']['no_results_text'] = [
'#type' => 'textfield',
'#title' => $this
->t('No results text'),
'#default_value' => $chosen_settings['no_results_text'],
];
return $element;
}