protected function EntityReferenceDragDropWidget::getSelectedOptions in Entity Reference Drag & Drop 2.x
Same name and namespace in other branches
- 8 src/Plugin/Field/FieldWidget/EntityReferenceDragDropWidget.php \Drupal\entityreference_dragdrop\Plugin\Field\FieldWidget\EntityReferenceDragDropWidget::getSelectedOptions()
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.
Overrides OptionsWidgetBase::getSelectedOptions
2 calls to EntityReferenceDragDropWidget::getSelectedOptions()
- EntityReferenceDragDropWidget::formElement in src/
Plugin/ Field/ FieldWidget/ EntityReferenceDragDropWidget.php - Returns the form for a single field widget.
- EntityReferenceDragDropWidget::getAvailableOptions in src/
Plugin/ Field/ FieldWidget/ EntityReferenceDragDropWidget.php - Gets a list of available entities for the field.
File
- src/
Plugin/ Field/ FieldWidget/ EntityReferenceDragDropWidget.php, line 201
Class
- EntityReferenceDragDropWidget
- Plugin implementation of the 'entityreference_dragdrop' widget.
Namespace
Drupal\entityreference_dragdrop\Plugin\Field\FieldWidgetCode
protected function getSelectedOptions(FieldItemListInterface $items, $delta = 0) {
// We need to check against a flat list of options.
$flat_options = OptGroup::flattenOptions($this
->getOptions($items
->getEntity()));
$selected_options = [];
foreach ($items as $item) {
$id = $item->{$this->column};
// Keep the value if it actually is in the list of options (needs to be
// checked against the flat list).
if (isset($flat_options[$id])) {
$selected_options[$id] = $flat_options[$id];
}
}
return $selected_options;
}