Problem/Motivation
Sometimes the address is empty or displayed without the country. This works with Drupal 10 and PHP 8.2, but not with Drupal 11 and PHP 8.3. Html::escape($country) cannot be null. Please add '#value' => Html::escape($countries[$country_code] ?? ''),
Warning : Undefined array key "" dans Drupal\address\Plugin\Field\FieldFormatter\AddressDefaultFormatter->viewElement() (/var/www/drupal/web/modules/contrib/address/src/Plugin/Field/FieldFormatter/AddressDefaultFormatter.php ligne 162)
TypeError : Drupal\Component\Utility\Html::escape(): Argument #1 ($text) must be of type string, null given, called in /var/www/drupal/web/modules/contrib/address/src/Plugin/Field/FieldFormatter/AddressDefaultFormatter.php on line 162 dans Drupal\Component\Utility\Html::escape() (ligne 431 de /var/www/drupal/web/core/lib/Drupal/Component/Utility/Html.php).Steps to reproduce
TBD
Proposed resolution
- Allow country to be empty (by setting)
- Show all address fields in widget
- Show the filled address fields in formatter
Remaining tasks
TBD
User interface changes
TBD
Introduced terminology
TBD
API changes
TBD
Data model changes
TBD
Release notes snippet
TBD
Possible contrib workaround
https://www.drupal.org/project/address_country_unknown provides an ugly workaround - would be better to solve or support this in the Address module
| Comment | File | Size | Author |
|---|---|---|---|
| Fixed_empty_country.patch | 961 bytes | lazzyvn |
Comments
Comment #2
aaron.ferris commentedIsn't Country a required field, as in, the address itself can't be added without it?
Could you please provide reproduction steps in getting the country to be empty? Migrated values perhaps?
Not that this change isn't the right way, im just wondering if this being empty could have consequences elsewhere.
Comment #3
lazzyvn commentedNo country is a required field, in my case I am using a custom form with ajax so it can be null. adding ?? '' is not a big deal to avoid a falta error.
Comment #4
anybodyCounty may not be empty in the address module, I think. And I guess maintainers won't change that...?
We had a similar issue with contacts where the country is unknown (which is a real world scenario). Maybe this also helps in your case: https://www.drupal.org/project/address_country_unknown
Of course I'd be happier to have a clean solution in address itself! ;)
I'll change the title and category accordingly, because I think the bug is caused by custom changes?
Comment #5
anybodyComment #6
anybodyComment #7
anybody