Problem/Motivation

When trying to add a form translation, the following error is thrown:
TypeError: Argument 1 passed to Drupal\Core\Render\Element::children() must be of the type array, null given, called in /app/modules/contrib/webform/src/WebformTranslationConfigManager.php on line 325 in Drupal\Core\Render\Element::children() (line 71 of /app/core/lib/Drupal/Core/Render/Element.php)

Steps to reproduce

  1. Install Drupal; tested on 9.1.8 and 8.9.15
  2. Install language and configuration translation
  3. Add a second language; ES
  4. Install of webform 6.0.3
  5. Add a new webform; /admin/structure/webform/add; test1
  6. Translate the webform; /admin/structure/webform/manage/test1/translate/es/add
  7. Result: The website encountered an unexpected error. Please try again later.

Log error message:
TypeError: Argument 1 passed to Drupal\Core\Render\Element::children() must be of the type array, null given, called in /app/web/modules/contrib/webform/src/WebformTranslationConfigManager.php on line 325 in Drupal\Core\Render\Element::children() (line 71 of /app/web/core/lib/Drupal/Core/Render/Element.php)

Testing the commits, the issue occurs from dev-6.x#2e3620e9
Error does not occur on 6.0.2 or dev-6.x#265d0a69

Issue fork webform-3212867

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

James.Shee created an issue. See original summary.

jrockowitz’s picture

Status: Active » Postponed (maintainer needs more info)

Sorry about the fatal bug.

Would you be able to post an example webform that can be used to replicate this issue?

paulocs’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new863 bytes
new4.64 KB

Attaching webform to reproduce the error and patch.

james.shee’s picture

Sorry about the confusion on the webform configuration. The error occurs even on an empty webform.

Tested patch from #3 works for webforms with elements; however, found another issue with empty webforms.

Scenario 1: Working
Webform contains elements

  1. Add a translation
  2. Make changes
  3. Save

Result:Webform Test1 elements saved.

Scenario 2: Broken
Webform is empty

  1. Add a translation
  2. Make changes or save without changes
  3. Save

Result: The website encountered an unexpected error. Please try again later.
Log messages:

  1. Notice: Undefined index: elements in Drupal\webform\WebformTranslationConfigManager::validateWebformForm() (line 277 of /app/web/modules/contrib/webform/src/WebformTranslationConfigManager.php)
  2. Warning: Invalid argument supplied for foreach() in Drupal\webform\WebformTranslationConfigManager::validateWebformForm() (line 278 of /app/web/modules/contrib/webform/src/WebformTranslationConfigManager.php)
  3. TypeError: Argument 1 passed to Drupal\webform\WebformTranslationConfigManager::mergeTranslationAndSourceElementsProperties() must be of the type array, null given, called in /app/web/modules/contrib/webform/src/WebformTranslationConfigManager.php on line 298 in Drupal\webform\WebformTranslationConfigManager->mergeTranslationAndSourceElementsProperties() (line 1022 of /app/web/modules/contrib/webform/src/WebformTranslationConfigManager.php)

This issue is present going back to 6.0.0

paulocs’s picture

Yeah! If the webform is empty (no elements) the error #4 occurs but it is not related with #3202515: Translation of custom body of email handler does not show as CKEditor.

// Remove any translation property that has not been translated.
    $translation_config_manager->mergeTranslationAndSourceElementsProperties($translation_elements, $source_elements);

was introduced in #3172735: Improve webform elements translation UI and refactor webform translation code

lomale@bluewin.ch’s picture

StatusFileSize
new7.68 KB

Hi, i hang into this

Drupal-Version: 8.9.15
PHP Version 7.4.16
Webform 6.0.3

I had the same problem, with a questionaire. file appended.

I hat it translated with not processed_text field in the questionaire.
Then I wanted to have this changed.

1 error : Processed text element can not be opened within a modal. Please see Issue #2741877: Nested modals don't work.

2 I couldn't open the translate option

I deleted the english translation, to translate it again.

Then I couldn't even come back to the translation.

The website encountered an unexpected error. Please try again later.

i had to rewrite the form and was then able to translate it with out processed text element.

Just as information

I will also append the php error

lomale@bluewin.ch’s picture

Issue tags: +php error
StatusFileSize
new4.81 KB

here the php Error txt

paulocs’s picture

Hello @lomale@bluewin.ch,
Did you try patch #3?

james.shee’s picture

Status: Needs review » Reviewed & tested by the community

@paulocs Ah, ok. Separate issue then. Going to update status to reviewed and tested by the community. Appreciate your fix and clarification.

paulocs’s picture

I opened another issue for when webforms have no elements.
#3213178: Unable to translate webforms if it has no elements.

joseph.olstad’s picture

RTBC +1, needed this fix for reasons described above
Thanks everyone!

If I don't apply patch 3, I get a nasty error below:

The website encountered an unexpected error. Please try again later.
TypeError: Argument 1 passed to Drupal\Core\Render\Element::children() must be of the type array, null given, called in html/modules/contrib/webform/src/WebformTranslationConfigManager.php on line 325 in Drupal\Core\Render\Element::children() (line 71 of core/lib/Drupal/Core/Render/Element.php).
jrockowitz’s picture

Status: Reviewed & tested by the community » Fixed

  • paulocs authored 2fbb4e5 on 6.x
    Issue #3212867 by paulocs, lomale@bluewin.ch: Unable to translate...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

rar9’s picture

patch 3# not cant be applied... is it because we still use 6.0.3 vs dev?

Is the 2x patched patch also required for a FUNCTIONAL Webform?

Gathering patches for dependencies. This might take a minute.
  - Installing drupal/webform (6.0.3): Extracting archive
  - Applying patches for drupal/webform
    https://www.drupal.org/project/webform/issues/3212867 (Unable to translate webforms 6.0.3)
   Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/project/webform/issues/3212867
    https://www.drupal.org/files/issues/2021-05-19/3213178-8.patch (Unable to translate webforms if it has no elements.)

dev.tim made their first commit to this issue’s fork.

gooddev’s picture

Version: 6.x-dev » 6.0.3
StatusFileSize
new756 bytes

I recognized following error when saving the translation of a webform with custom elements in it.

TypeError: Argument 2 passed to Drupal\webform\WebformTranslationConfigManager::mergeTranslationAndSourceElementsProperties() must be of the type array, string given, called in /var/www/html/web/modules/contrib/webform/src/WebformTranslationConfigManager.php on line 1032 in Drupal\webform\WebformTranslationConfigManager->mergeTranslationAndSourceElementsProperties() (line 1022 of modules/contrib/webform/src/WebformTranslationConfigManager.php).

so i added a type check for "$source_element" to get sure this is an array. (see patch 3212867-16.patch).

gooddev’s picture

StatusFileSize
new756 bytes
gooddev’s picture

StatusFileSize
new751 bytes

sorry for the spam, cannot override wrong patch, here is the correct one now "3212867-19.patch"

jrockowitz’s picture

Status: Closed (fixed) » Needs review

@dev.tim Your patch makes perfect sense. I am willing to bet all the tests pass.

  • dev.tim authored ffbfb25 on 6.x
    Issue #3212867 by dev.tim, paulocs, lomale@bluewin.ch, jrockowitz:...
jrockowitz’s picture

Status: Needs review » Fixed
daften’s picture

Can I ask why 2 separate issues were fixed in the same issue? This makes it quite hard to figure out what patch to use when still on 6.0.3. Luckily this was a short comment list, but imo this should be avoided. The issue reported in #3212867-17: Unable to translate webforms 6.0.3 should have been a separate issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

ShenHua’s picture

This is still broken in 6.0.4. Even tho the #19 patch is already implemented.

I am getting:

The website encountered an unexpected error. Please try again later.
TypeError: Argument 4 passed to Drupal\webform\Twig\WebformTwigExtension::webformToken() must be of the type array, null given, called in C:\wamp64\www\sites\default\files\php\twig\610f13ae913be___string_template__11faf7_OJQOI0oAxrKpAk_duG8d5UD4z\5CMHFghPqS58DtIQXQSAsaNrIWLE4x4hePH7tUy5Hc0.php on line 51 in Drupal\webform\Twig\WebformTwigExtension->webformToken() (line 102 of modules\webform\src\Twig\WebformTwigExtension.php).
Drupal\webform\Twig\WebformTwigExtension->webformToken('[webform_submission:created]', NULL, Array, NULL) (Line: 51)
__TwigTemplate_05a1d0d8b06e49dcd06f6c1651e4d3b6597728c9c09ac47f3473f787e155f3d3->doDisplay(Array, Array) (Line: 405)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 378)
Twig\Template->display(Array) (Line: 390)
Twig\Template->render(Array, Array) (Line: 45)
Twig\TemplateWrapper->render(Array) (Line: 235)
Drupal\Core\Template\TwigEnvironment->renderInline('{# inline_template_start #}

     Submitted on {{ webform_token('[webform_submission:created]', webform_submission, [], options) }}
    Submitted by: {{ webform_token('[webform_submission:user]', webform_submission, [], options) }}...

----

The condition for this error to appear is probably why this was missed.
In general, I am able to translate the webform.

BUT

After I add the TWIG template to the body of the message in email handlers. Then I get this error whenever I try to translate from that point on.

Possible duplicate: (I am going to check if the patch there helps, and report back, also, if you need any more code from me let me know).

https://www.drupal.org/project/webform/issues/3215471

UPDATE:
I am still experiencing the same error as #4 of issue 3215471.

Both the patch from here, and the patch from there are already implemented in 6.0.4, so they're not solving the issue.
UPDATE:

Good news! Turns out that the issue was with my TWIG code.
The problem is that the TWIG code "worked" for sending the email and there was nothing notifying me that there's a mistake... until I reached the translate step.

Anyway, the issue was that there were some parts of the code resulting in NULLS (obviously when I look at it now):

wrong:
{{ webform_token('[webform_submission:values:message]', webform_submission, [], options) }}

correct:
{{ webform_token('[webform_submission:values:message]', webform_submission) }}

leup’s picture

Thank you @ShenHua ! You saved me a lot of time, I had the same issue and was able to fix it with your solution. Again, thanks !