function OptionsWidgetBase::getOptions
Same name in other branches
- 8.9.x core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php \Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase::getOptions()
- 10 core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php \Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase::getOptions()
- 11.x core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php \Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase::getOptions()
Returns the array of options for the widget.
Parameters
\Drupal\Core\Entity\FieldableEntityInterface $entity: The entity for which to return options.
Return value
array The array of options for the widget.
3 calls to OptionsWidgetBase::getOptions()
- OptionsButtonsWidget::formElement in core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldWidget/ OptionsButtonsWidget.php - Returns the form for a single field widget.
- OptionsSelectWidget::formElement in core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldWidget/ OptionsSelectWidget.php - Returns the form for a single field widget.
- OptionsWidgetBase::getSelectedOptions in core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldWidget/ OptionsWidgetBase.php - Determines selected options from the incoming field values.
File
-
core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldWidget/ OptionsWidgetBase.php, line 132
Class
- OptionsWidgetBase
- Base class for the 'options_*' widgets.
Namespace
Drupal\Core\Field\Plugin\Field\FieldWidgetCode
protected function getOptions(FieldableEntityInterface $entity) {
if (!isset($this->options)) {
// Limit the settable options for the current user account.
$options = $this->fieldDefinition
->getFieldStorageDefinition()
->getOptionsProvider($this->column, $entity)
->getSettableOptions(\Drupal::currentUser());
// Add an empty option if the widget needs one.
if ($empty_label = $this->getEmptyLabel()) {
$options = [
'_none' => $empty_label,
] + $options;
}
$module_handler = \Drupal::moduleHandler();
$context = [
'fieldDefinition' => $this->fieldDefinition,
'entity' => $entity,
];
$module_handler->alter('options_list', $options, $context);
array_walk_recursive($options, [
$this,
'sanitizeLabel',
]);
// Options might be nested ("optgroups"). If the widget does not support
// nested options, flatten the list.
if (!$this->supportsGroups()) {
$options = OptGroup::flattenOptions($options);
}
$this->options = $options;
}
return $this->options;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.