protected function SelectOrOtherWidgetBase::getSelectedOptions in Select (or other) 8.3
Determines selected options from the incoming field values.
Parameters
\Drupal\Core\Field\FieldItemListInterface $items: The field values.
Return value
array The array of corresponding selected options.
1 call to SelectOrOtherWidgetBase::getSelectedOptions()
- SelectOrOtherWidgetBase::formElement in src/
Plugin/ Field/ FieldWidget/ SelectOrOtherWidgetBase.php - Returns the form for a single field widget.
File
- src/
Plugin/ Field/ FieldWidget/ SelectOrOtherWidgetBase.php, line 209 - Contains \Drupal\select_or_other\Plugin\Field\FieldWidget\SelectOrOtherWidgetBase.
Class
- SelectOrOtherWidgetBase
- Base class for the 'select_or_other_*' widgets.
Namespace
Drupal\select_or_other\Plugin\Field\FieldWidgetCode
protected function getSelectedOptions(FieldItemListInterface $items) {
$selected_options = [];
foreach ($items as $item) {
$selected_options[] = $item->{$this
->getColumn()};
}
$selected_options = $this
->prepareSelectedOptions($selected_options);
if ($selected_options) {
// We need to check against a flat list of options.
$flattened_options = $this
->flattenOptions($this
->getOptions());
foreach ($selected_options as $key => $selected_option) {
// Remove the option if it does not exist in the options.
if (!isset($flattened_options[$selected_option])) {
unset($selected_options[$key]);
}
}
}
return $selected_options;
}