Form translation error - Element::children() must be of the type array, null given

Created on 7 November 2018, over 6 years ago
Updated 30 January 2023, over 2 years ago

Hi,

I found some bug with content translation when new form should be generate. I made patch I need review.

Scenario:

On website using Drupal core 8.6.2, have 3 different languages (English, Danish and German) and using Drupal Commerce 2.11.

After updating Drupal Commerce to 2.11, if user does not have permission to "View stores" and goes to edit product he will get this page:
http://prntscr.com/lfemp8

and that is ok if default product language is the same like site language. If you go to another language on website that is not same as dafault product language you will get this error:

TypeError: Argument 1 passed to Drupal\Core\Render\Element::children() must be of the type array, null given, called in /home/webshop/public_html/core/modules/content_translation/src/ContentTranslationHandler.php on line 530 in Drupal\Core\Render\Element::children() (line 71 of /home/webshop/public_html/core/lib/Drupal/Core/Render/Element.php) #0 /home/webshop/public_html/core/modules/content_translation/src/ContentTranslationHandler.php(530): Drupal\Core\Render\Element::children(NULL) #1 /home/webshop/public_html/modules/contrib/commerce/modules/product/src/ProductTranslationHandler.php(20): Drupal\content_translation\ContentTranslationHandler->entityFormAlter(Array, Object(Drupal\Core\Form\FormState), Object(Drupal\commerce_product\Entity\Product)) #2 /home/webshop/public_html/core/modules/content_translation/content_translation.module(326): Drupal\commerce_product\ProductTranslationHandler->entityFormAlter(Array, Object(Drupal\Core\Form\FormState), Object(Drupal\commerce_product\Entity\Product)) #3 /home/webshop/public_html/core/lib/Drupal/Core/Extension/ModuleHandler.php(539): content_translation_form_alter(Array, Object(Drupal\Core\Form\FormState), 'commerce_produc...') #4 /home/webshop/public_html/core/lib/Drupal/Core/Form/FormBuilder.php(834): Drupal\Core\Extension\ModuleHandler->alter('form', Array, Object(Drupal\Core\Form\FormState), 'commerce_produc...') #5 /home/webshop/public_html/core/lib/Drupal/Core/Form/FormBuilder.php(276): Drupal\Core\Form\FormBuilder->prepareForm('commerce_produc...', Array, Object(Drupal\Core\Form\FormState)) #6 /home/webshop/public_html/core/lib/Drupal/Core/Controller/FormController.php(93): Drupal\Core\Form\FormBuilder->buildForm('commerce_produc...', Object(Drupal\Core\Form\FormState)) #7 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch)) #8 /home/webshop/public_html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array) #9 /home/webshop/public_html/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #10 /home/webshop/public_html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #11 /home/webshop/public_html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) #12 /home/webshop/vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #13 /home/webshop/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #14 /home/webshop/public_html/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #15 /home/webshop/public_html/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #16 /home/webshop/public_html/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #17 /home/webshop/public_html/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #18 /home/webshop/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #19 /home/webshop/public_html/core/lib/Drupal/Core/DrupalKernel.php(665): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #20 /home/webshop/public_html/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #21 {main}.

I tested for some different scenarios and this only occurs if default product language is different then website default language. For example if default product language is "EN" and default website language is "DA" you will get this error.

Patch to fix this bug is attach, please someone to review.
Thanks.

🐛 Bug report
Status

Needs work

Version

10.1

Component
Content translation 

Last updated 3 days ago

No maintainer
Created by

🇷🇸Serbia bojan.m

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.

  • The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • 🇮🇹Italy trickfun

    Patch works.
    Thank you

  • Status changed to Postponed: needs info about 1 year ago
  • 🇮🇳India samit.310@gmail.com

    Hello,

    I checked it on Both Drupal 10.2.7 with Commerce 8.x-2.39 also validated it in Drupal 11, it is working as expected. Looks like no need to do any code changes in Drupal 10 and Drupal 11.

    Please provide reproducible steps for Drupal 10 or Drupal 11 if some once facing it.

    Thanks
    Samit K.

  • Status changed to Closed: outdated 9 days ago
  • 🇺🇸United States smustgrave

    Since there's been no follow up going to close out. If still a bug in D11 please re-open.

Production build 0.71.5 2024