Inline form errors breaks Commerce Promotions

Created on 18 March 2024, 3 months ago
Updated 7 June 2024, 17 days ago

Problem/Motivation

Initially filed in the commerce queue πŸ› Promotions do not apply - TypeError: implode(): Argument #1 ($pieces) must be of type array, string given in implode() Active , but it may very well be related to a recent change in Drupal core's inline_form_errors.

When inline_form_errors is enabled, Commerce promotions do not apply either via coupons or automatically.

The log displays an error on attempting to use a coupon:
TypeError: implode(): Argument #1 ($pieces) must be of type array, string given in implode() (line 26 of /var/www/xxx/core/lib/Drupal/Core/Form/FormElementHelper.php).

Full stack trace:

#0 /var/www/***/core/lib/Drupal/Core/Form/FormElementHelper.php(26): implode()
#1 /var/www/***/core/lib/Drupal/Core/Form/FormElementHelper.php(29): Drupal\Core\Form\FormElementHelper::getElementByName()
#2 /var/www/***/core/lib/Drupal/Core/Form/FormElementHelper.php(29): Drupal\Core\Form\FormElementHelper::getElementByName()
#3 /var/www/***/core/lib/Drupal/Core/Form/FormElementHelper.php(29): Drupal\Core\Form\FormElementHelper::getElementByName()
#4 /var/www/***/core/lib/Drupal/Core/Form/FormElementHelper.php(29): Drupal\Core\Form\FormElementHelper::getElementByName()
#5 /var/www/***/core/lib/Drupal/Core/Form/FormElementHelper.php(29): Drupal\Core\Form\FormElementHelper::getElementByName()
#6 /var/www/***/core/lib/Drupal/Core/Form/FormElementHelper.php(29): Drupal\Core\Form\FormElementHelper::getElementByName()
#7 /var/www/***/core/modules/inline_form_errors/src/FormErrorHandler.php(81): Drupal\Core\Form\FormElementHelper::getElementByName()
#8 /var/www/***/core/lib/Drupal/Core/Form/FormErrorHandler.php(23): Drupal\inline_form_errors\FormErrorHandler->displayErrorMessages()
#9 /var/www/***/core/lib/Drupal/Core/Form/FormValidator.php(199): Drupal\Core\Form\FormErrorHandler->handleFormErrors()
#10 /var/www/***/core/lib/Drupal/Core/Form/FormValidator.php(119): Drupal\Core\Form\FormValidator->finalizeValidation()
#11 /var/www/***/core/lib/Drupal/Core/Form/FormBuilder.php(593): Drupal\Core\Form\FormValidator->validateForm()
#12 /var/www/***/core/lib/Drupal/Core/Form/FormBuilder.php(325): Drupal\Core\Form\FormBuilder->processForm()
#13 /var/www/***/core/lib/Drupal/Core/Form/FormBuilder.php(224): Drupal\Core\Form\FormBuilder->buildForm()
#14 /var/www/***/modules/contrib/commerce/modules/checkout/src/Controller/CheckoutController.php(143): Drupal\Core\Form\FormBuilder->getForm()
#15 [internal function]: Drupal\commerce_checkout\Controller\CheckoutController->formPage()
#16 /var/www/***/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#17 /var/www/***/core/lib/Drupal/Core/Render/Renderer.php(627): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#18 /var/www/***/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\Core\Render\Renderer->executeInRenderContext()
#19 /var/www/***/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#20 /var/www/***/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#21 /var/www/***/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#22 /var/www/***/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle()
#23 /var/www/***/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#24 /var/www/***/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#25 /var/www/***/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\ContentLength->handle()
#26 /var/www/***/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
#27 /var/www/***/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle()
#28 /var/www/***/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#29 /var/www/***/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#30 /var/www/***/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle()
#31 /var/www/***/core/lib/Drupal/Core/DrupalKernel.php(704): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
#32 /var/www/***/index.php(19): Drupal\Core\DrupalKernel->handle()
#33 {main}

Steps to reproduce

Install Drupal 10.2.4
Install latest version of commerce and related modules to display promotions
Enable the inline_form_errors module
Create a promotion without any conditions and try to apply it.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component
Inline form errorsΒ  β†’

Last updated 17 days ago

  • Maintained by
  • πŸ‡³πŸ‡±Netherlands @dmsmidt
Created by

πŸ‡ΉπŸ‡­Thailand AlfTheCat

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

Comments & Activities

  • Issue created by @AlfTheCat
  • Status changed to Postponed: needs info 3 months ago
  • πŸ‡ΊπŸ‡ΈUnited States cilefen

    Which form element is being rendered when this occurs and what exactly is the string that is the string that is expected to be an array?

  • Status changed to Active 3 months ago
  • πŸ‡ΉπŸ‡­Thailand AlfTheCat

    Hi @cilefen,

    It's possible to trigger the watchdog error by requiring a coupon on the Commerce promotion and then applying it via the coupon form on Commerce checkout. However, interestingly, the way commerce works is that it can apply discounts without a coupon and show the calculated product price in the front end already including the discount. In my case, I am using this for a b2b feature where wholesale roles automatically get a discount applied and consequently, see lower prices on display without using coupons. There is no form involved when viewing products in a view or on a page, yet with inline_form_errors the promotions are not applied. Uninstalling the module quickly fixes that issue.

    I don't know what string is expected, I'm applying a 90% discount without any conditions for testing purposes.

    Unfortunately, this is the extent of my insight into this issue and I hope it helps. I'm updating the issue status perhaps prematurely.

  • Status changed to Postponed: needs info 3 months ago
  • πŸ‡ΊπŸ‡ΈUnited States cilefen

    Technically we need the information I asked for in #2 if this is a core bug.

  • πŸ‡ΊπŸ‡ΈUnited States xjm
Production build 0.69.0 2024