protected function ReferenceWidget::getOptions in Select (or other) 4.x
Same name and namespace in other branches
- 8 src/Plugin/Field/FieldWidget/ReferenceWidget.php \Drupal\select_or_other\Plugin\Field\FieldWidget\ReferenceWidget::getOptions()
Returns the array of options for the widget.
Parameters
\Drupal\Core\Entity\FieldableEntityInterface $entity: The entity this widget is used for.
Return value
array The array of available options for the widget. The array of available options for the widget.
Overrides WidgetBase::getOptions
File
- src/
Plugin/ Field/ FieldWidget/ ReferenceWidget.php, line 113
Class
- ReferenceWidget
- Plugin implementation of the 'select_or_other_reference' widget.
Namespace
Drupal\select_or_other\Plugin\Field\FieldWidgetCode
protected function getOptions(FieldableEntityInterface $entity = NULL) {
$options = [];
// Prepare properties to use for loading.
$entity_storage = $this
->getEntityStorage();
$bundle_key = $this
->getBundleKey();
$target_bundles = $this
->getSelectionHandlerSetting('target_bundles');
$properties = [
$bundle_key => $target_bundles,
];
$entities = $entity_storage
->loadByProperties($properties);
// Prepare the options.
foreach ($entities as $entity) {
$options["{$entity->label()} ({$entity->id()})"] = $entity
->label();
}
return $options;
}