From 6e000f99d71a0071bd1af9f40a5acd16bbbaea82 Mon Sep 17 00:00:00 2001 From: Bojan Zivanovic Date: Wed, 13 Sep 2017 17:33:39 +0200 Subject: [PATCH] Issue #2908571 by bojanz: ProfileSelect should validate that the default country is allowed --- modules/order/src/Element/ProfileSelect.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/order/src/Element/ProfileSelect.php b/modules/order/src/Element/ProfileSelect.php index d530915637..6aacf1c649 100644 --- a/modules/order/src/Element/ProfileSelect.php +++ b/modules/order/src/Element/ProfileSelect.php @@ -85,6 +85,12 @@ public static function processForm(array $element, FormStateInterface $form_stat if (!is_array($element['#available_countries'])) { throw new \InvalidArgumentException('The commerce_profile_select #available_countries property must be an array.'); } + // Make sure that the specified default country is available. + if (!empty($element['#default_country']) && !empty($element['#available_countries'])) { + if (!in_array($element['#default_country'], $element['#available_countries'])) { + $element['#default_country'] = NULL; + } + } $element['#profile'] = $element['#default_value']; $form_display = EntityFormDisplay::collectRenderDisplay($element['#profile'], 'default');