protected function ReferenceWidget::getOptions in Select (or other) 8.3
Returns the array of options for the widget.
Return value
array The array of available options for the widget.
Overrides SelectOrOtherWidgetBase::getOptions
File
- src/
Plugin/ Field/ FieldWidget/ EntityReference/ ReferenceWidget.php, line 82 - 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 getOptions() {
$options = [];
// Prepare properties to use for loading.
$entityStorage = $this
->getEntityStorage();
$bundle_key = $this
->getBundleKey();
$target_bundles = $this
->getSelectionHandlerSetting('target_bundles');
$properties = [
$bundle_key => $target_bundles,
];
$entities = $entityStorage
->loadByProperties($properties);
// Prepare the options.
foreach ($entities as $entity) {
$options["{$entity->label()} ({$entity->id()})"] = $entity
->label();
}
return $options;
}