- Issue created by @xpersonas
When I use the checkbox/radio format, the "- None -" option is often missing.
I can't tell why some of my fields have it and some do not. They are all taxonomy reference fields with the exact same settings.
However, a fresh test reproduces the error for me.
Create a new entity reference field for a taxonomy vocabulary.
Change the field to "select or other" in the form display.
Change select list to checkboxes.
The "- None -" option is missing.
I have altered this code to check that the array contains no default items, rather than just if the array exists.
protected static function addEmptyOption(array &$element) {
if ((!isset($element['#no_empty_option']) || !$element['#no_empty_option']) && !$element['#multiple']) {
if (!$element['#required'] && !count($element['#default_value']) > 0) {
$element['select']['#options'] = ['' => t('- None -')] + $element['select']['#options'];
}
else {
$element['select']['#value'] = [];
}
}
}
This seems to work for me. I would welcome some thoughts on it or if this is an issue for anyone else.
I can also confirm this issue, however, I don't think it's 100% directly related to my issue:
https://www.drupal.org/project/select_or_other/issues/3260054
π
- None - option for default value in field settings form is being removed
Active
Active
4.0
Code