protected function Widget::getEmptyOption in Select (or other) 8.3
Returns the empty option to add to the list of options, if any.
Return value
string|null Either static::OPTIONS_EMPTY_NONE, static::OPTIONS_EMPTY_SELECT, or NULL.
Overrides SelectOrOtherWidgetBase::getEmptyOption
1 call to Widget::getEmptyOption()
- Widget::getOptions in src/
Plugin/ Field/ FieldWidget/ Widget.php - Returns the array of options for the widget.
File
- src/
Plugin/ Field/ FieldWidget/ Widget.php, line 192 - Contains \Drupal\select_or_other\Plugin\Field\FieldWidget\Widget.
Class
- Widget
- Plugin implementation of the 'select_or_other' widget.
Namespace
Drupal\select_or_other\Plugin\Field\FieldWidgetCode
protected function getEmptyOption() {
if ($this
->isMultiple()) {
// Multiple select: add a 'none' option for non-required fields.
if (!$this
->isRequired()) {
return static::SELECT_OR_OTHER_EMPTY_NONE;
}
}
else {
// Single select: add a 'none' option for non-required fields,
// and a 'select a value' option for required fields that do not come
// with a value selected.
if (!$this
->isRequired()) {
return static::SELECT_OR_OTHER_EMPTY_NONE;
}
if (!$this
->hasValue()) {
return static::SELECT_OR_OTHER_EMPTY_SELECT;
}
}
return NULL;
}