Commit fe9d8c91 authored by bojanz's avatar bojanz
Browse files

Issue #2689089 followup: Improve the interaction between #available_countries...

Issue #2689089 followup: Improve the interaction between #available_countries and a non-available country

Prevents a crash when there's only one available country.
parent 305d9a27
......@@ -131,6 +131,10 @@ class Address extends FormElement {
$country_list = $full_country_list;
if (!empty($element['#available_countries'])) {
$available_countries = $element['#available_countries'];
if (!empty($element['#default_value']['country_code'])) {
// The current country should always be available.
$available_countries[] = $element['#default_value']['country_code'];
}
$available_countries = array_combine($available_countries, $available_countries);
$country_list = array_intersect_key($country_list, $available_countries);
}
......@@ -141,15 +145,6 @@ class Address extends FormElement {
// is empty even though the field is required.
$value['country_code'] = key($country_list);
}
if (!empty($value['country_code']) && !isset($country_list[$value['country_code']])) {
// This item's country is no longer available. Add it back to the top
// of the list to ensure all data is displayed properly. The validator
// can then prevent the save and tell the user to change the country.
$missing_element = [
$value['country_code'] => $full_country_list[$value['country_code']],
];
$country_list = $missing_element + $country_list;
}
$element += [
'#prefix' => '<div id="' . $wrapper_id . '">',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment