protected function SelectOtherWidget::getOptions in CCK Select Other 8
Add the Other option to the allowed values to form the select list option array.
This method MUST override OptionsWidgetBase because that class is tightly coupled with its options widgets. DrupalWTF.
Overrides OptionsWidgetBase::getOptions
2 calls to SelectOtherWidget::getOptions()
- SelectOtherWidget::formElement in src/
Plugin/ Field/ FieldWidget/ SelectOtherWidget.php - Returns the form for a single field widget.
- SelectOtherWidget::getDefaultValue in src/
Plugin/ Field/ FieldWidget/ SelectOtherWidget.php - Get the default values from the items for the form elements.
File
- src/
Plugin/ Field/ FieldWidget/ SelectOtherWidget.php, line 224
Class
- SelectOtherWidget
- Plugin implementation of the 'cck_select_other' widget.
Namespace
Drupal\cck_select_other\Plugin\Field\FieldWidgetCode
protected function getOptions(FieldableEntityInterface $entity) {
if (!isset($this->options)) {
// Limit the settable options for the current user account.
$options = $this->fieldDefinition
->getFieldStorageDefinition()
->getOptionsProvider($this->column, $entity)
->getSettableOptions(\Drupal::currentUser());
$options['other'] = Html::escape($this
->getSetting('other_label'));
// Add an empty option if the widget needs one.
if ($empty_option = $this
->getEmptyOption()) {
$options = [
'_none' => $empty_option,
] + $options;
}
$module_handler = \Drupal::moduleHandler();
$context = [
'fieldDefinition' => $this->fieldDefinition,
'entity' => $entity,
];
$module_handler
->alter('options_list', $options, $context);
array_walk_recursive($options, [
$this,
'sanitizeLabel',
]);
// Options might be nested ("optgroups"). If the widget does not support
// nested options, flatten the list.
if (!$this
->supportsGroups()) {
$options = $this
->flattenOptions($options);
}
$this->options = $options;
}
return $this->options;
}