Problem/Motivation
Not all countries have an administrative area (e.g., State or Province). A critical error occurs during checkout if the address field for the administrative area is not set, and there is any other error during form validation.
The website encountered an unexpected error. Please try again later.
TypeError: implode(): Argument #1 ($pieces) must be of type array, string given in implode() (line 26 of core/lib/Drupal/Core/Form/FormElementHelper.php).
implode('][', NULL) (Line: 26)
Drupal\Core\Form\FormElementHelper::getElementByName('payment_information][add_payment_method][billing_information][copy_fields][tax_number][0', Array) (Line: 29)
Drupal\Core\Form\FormElementHelper::getElementByName('payment_information][add_payment_method][billing_information][copy_fields][tax_number][0', Array) (Line: 29)
Drupal\Core\Form\FormElementHelper::getElementByName('payment_information][add_payment_method][billing_information][copy_fields][tax_number][0', Array) (Line: 29)
Drupal\Core\Form\FormElementHelper::getElementByName('payment_information][add_payment_method][billing_information][copy_fields][tax_number][0', Array) (Line: 29)
Drupal\Core\Form\FormElementHelper::getElementByName('payment_information][add_payment_method][billing_information][copy_fields][tax_number][0', Array) (Line: 29)
Drupal\Core\Form\FormElementHelper::getElementByName('payment_information][add_payment_method][billing_information][copy_fields][tax_number][0', Array) (Line: 29)
Drupal\Core\Form\FormElementHelper::getElementByName('payment_information][add_payment_method][billing_information][copy_fields][tax_number][0', Array) (Line: 81)
Drupal\inline_form_errors\FormErrorHandler->displayErrorMessages(Array, Object) (Line: 23)
Drupal\Core\Form\FormErrorHandler->handleFormErrors(Array, Object) (Line: 199)
Drupal\Core\Form\FormValidator->finalizeValidation(Array, Object, 'commerce_checkout_flow_multistep_default') (Line: 119)
Drupal\Core\Form\FormValidator->validateForm('commerce_checkout_flow_multistep_default', Array, Object) (Line: 593)
Drupal\Core\Form\FormBuilder->processForm('commerce_checkout_flow_multistep_default', Array, Object) (Line: 325)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 224)
Drupal\Core\Form\FormBuilder->getForm(Object, 'order_information') (Line: 143)
Drupal\commerce_checkout\Controller\CheckoutController->formPage(Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Steps to reproduce
- Proceed to checkout, selecting a country without an administrative area (e.g., Portugal).
- Choose "Stripe" as the payment method.
- Enter an invalid VAT number in the "Tax number" field.
- Upon submission, the site crashes.
Proposed resolution
Validate if $element['address']['widget'][0]['address'] is set.