protected function ReferenceWidget::prepareSelectedOptions in Select (or other) 8.3
Prepares selected options for comparison to the available options.
Sometimes widgets have to change the keys of their available options. This method allows those widgets to do the same with the selected options to ensure they actually end up selected in the widget.
Parameters
array $options: The options to prepare.
Return value
array The prepared option.
Overrides SelectOrOtherWidgetBase::prepareSelectedOptions
File
- src/
Plugin/ Field/ FieldWidget/ EntityReference/ ReferenceWidget.php, line 104 - Contains \Drupal\select_or_other\Plugin\Field\FieldWidget\EntityReference\ReferenceWidget.
Class
- ReferenceWidget
- Plugin implementation of the 'select_or_other_reference' widget.
Namespace
Drupal\select_or_other\Plugin\Field\FieldWidget\EntityReferenceCode
protected function prepareSelectedOptions(array $options) {
$prepared_options = [];
$entities = $this
->getEntityStorage()
->loadMultiple($options);
foreach ($entities as $entity) {
$prepared_options[] = "{$entity->label()} ({$entity->id()})";
}
return $prepared_options;
}