line 1112 of /app/web/core/lib/Drupal/Core/Form/FormState.php when postal code validation fails

Created on 15 October 2020, over 4 years ago
Updated 11 October 2024, 6 months ago

Problem/Motivation

In Commerce, you can hide fields in the Address field of the customer Profile (/config/people/profile-types/manage/customer/fields/profile.customer.address).

Commerce Stripe doesn't respect this, which causes several errors to be printed to the screen when checking out and form validation fails (for example, when you enter a postal code that doesn't validate).

Steps to reproduce

1. Configure a basic Commerce store with this module.
2. Disable all fields but country + postal code in the profile.
3. Add a product to the card and try to check out. When entering payment info, enter an incorrect postal code for your country.
4. You get a ton of form 1112 errors:

Notice: Undefined index: #parents in Drupal\Core\Form\FormState->getError() (line 1112 of /app/web/core/lib/Drupal/Core/Form/FormState.php).

Warning: Invalid argument supplied for foreach() in Drupal\Core\Form\FormState->getError() (line 1112 of /app/web/core/lib/Drupal/Core/Form/FormState.php).:

Proposed resolution

This was partially fixed in a separate issue with isset(), so I propose doing the same thing again.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

🇯🇵Japan ptmkenny

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇹Italy trickfun

    I have same error.
    I cant apply path on 1.2-rc1 and dev version

    Warning: Undefined array key "#parents" in Drupal\Core\Form\FormState->setError() (line 1168 of /var/www/html/web/core/lib/Drupal/Core/Form/FormState.php)
    #0 /var/www/html/web/core/includes/bootstrap.inc(166): _drupal_error_handler_real(2, 'Undefined array...', '/var/www/html/w...', 1168)
    #1 /var/www/html/web/core/lib/Drupal/Core/Form/FormState.php(1168): _drupal_error_handler(2, 'Undefined array...', '/var/www/html/w...', 1168)
    #2 /var/www/html/web/core/lib/Drupal/Core/Field/WidgetBase.php(582): Drupal\Core\Form\FormState->setError(Array, Object(Drupal\Core\StringTranslation\TranslatableMarkup))
    #3 /var/www/html/web/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php(291): Drupal\Core\Field\WidgetBase->flagErrors(Object(Drupal\address\Plugin\Field\FieldType\AddressFieldItemList), Object(Symfony\Component\Validator\ConstraintViolationList), Array, Object(Drupal\Core\Form\FormState))
    #4 /var/www/html/web/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php(273): Drupal\Core\Entity\Entity\EntityFormDisplay->flagWidgetsErrorsFromViolations(Object(Drupal\Core\Entity\EntityConstraintViolationList), Array, Object(Drupal\Core\Form\FormState))
    #5 /var/www/html/web/modules/contrib/commerce/modules/order/src/Plugin/Commerce/InlineForm/CustomerProfile.php(341): Drupal\Core\Entity\Entity\EntityFormDisplay->validateFormValues(Object(Drupal\profile\Entity\Profile), Array, Object(Drupal\Core\Form\FormState))
    #6 /var/www/html/web/modules/contrib/commerce/src/Plugin/Commerce/InlineForm/InlineFormBase.php(145): Drupal\commerce_order\Plugin\Commerce\InlineForm\CustomerProfile->validateInlineForm(Array, Object(Drupal\Core\Form\FormState))
    #7 [internal function]: Drupal\commerce\Plugin\Commerce\InlineForm\InlineFormBase::runValidate(Array, Object(Drupal\Core\Form\FormState), Array)
    #8 /var/www/html/web/core/lib/Drupal/Core/Form/FormValidator.php(281): call_user_func_array(Array, Array)
    #9 /var/www/html/web/core/lib/Drupal/Core/Form/FormValidator.php(238): Drupal\Core\Form\FormValidator->doValidateForm(Array, Object(Drupal\Core\Form\FormState))
    #10 /var/www/html/web/core/lib/Drupal/Core/Form/FormValidator.php(238): Drupal\Core\Form\FormValidator->doValidateForm(Array, Object(Drupal\Core\Form\FormState))
    #11 /var/www/html/web/core/lib/Drupal/Core/Form/FormValidator.php(118): Drupal\Core\Form\FormValidator->doValidateForm(Array, Object(Drupal\Core\Form\FormState), 'commerce_checko...')
    #12 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(593): Drupal\Core\Form\FormValidator->validateForm('commerce_checko...', Array, Object(Drupal\Core\Form\FormState))
    #13 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(326): Drupal\Core\Form\FormBuilder->processForm('commerce_checko...', Array, Object(Drupal\Core\Form\FormState))
    #14 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(224): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\MultistepDefault), Object(Drupal\Core\Form\FormState))
    #15 /var/www/html/web/modules/contrib/commerce/modules/checkout/src/Controller/CheckoutController.php(143): Drupal\Core\Form\FormBuilder->getForm(Object(Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\MultistepDefault), 'order_informati...')
    #16 [internal function]: Drupal\commerce_checkout\Controller\CheckoutController->formPage(Object(Drupal\Core\Routing\RouteMatch))
    #17 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
    #18 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(638): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #19 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
    #20 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
    #21 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #22 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
    #23 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #24 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #25 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #26 /var/www/html/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #27 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #28 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #29 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #30 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #31 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #32 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #33 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #34 /var/www/html/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
    #35 {main}
    

    Step to reproduce:
    - Add product to cart
    - Go to cart
    - Go to checkout
    - Select Italy as country in shipping information
    - Select one province
    - Change country. Ex: select Germany

    form doesn't change.
    thank you

Production build 0.71.5 2024