Fatal error empty country

Created on 4 May 2025, 10 days ago

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).
🐛 Bug report
Status

Active

Version

2.1

Component

Code

Created by

🇫🇷France lazzyvn paris

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @lazzyvn
  • 🇬🇧United Kingdom aaron.ferris

    Isn'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.

  • 🇫🇷France lazzyvn paris

    No 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.

Production build 0.71.5 2024