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

Created on 7 November 2018, over 5 years ago
Updated 15 June 2024, 13 days 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

11.0 🔥

Component
Content translation 

Last updated 2 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.

Production build 0.69.0 2024