TypeError unflatten() must be of type array, null given

Created on 26 March 2025, about 1 month ago

Problem/Motivation

When user selected custom fields for translation but fields in some cases do not return any data for translation fatal error occurs.

TypeError: Drupal\tmgmt\Data::unflatten(): Argument #1 ($flattened_data) must be of type array, null given,
called in /web/modules/contrib/tmgmt_deepl/src/Plugin/tmgmt/Translator/DeeplTranslator.php on line 605 in
Drupal\tmgmt\Data->unflatten() (line 93 of /web/modules/contrib/tmgmt/src/Data.php).

πŸ› Bug report
Status

Active

Version

2.2

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine andriic

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

Merge Requests

Comments & Activities

  • Issue created by @andriic
  • Pipeline finished with Success
    about 1 month ago
    Total: 340s
    #458257
  • πŸ‡©πŸ‡ͺGermany SteffenR Germany

    Thanks for the finding. We never run into those issues on our projects.
    I would suggest du check beforehand, if $results['translation'] is really and array and is not empty. Otherwise, we would add empty translateData to the job_item, which is not neccessary.

  • πŸ‡ΊπŸ‡¦Ukraine andriic

    hi @steffenr,
    If we will not add translatedData to the job it will stay in "In progress" state forever, which is not correct since there's nothing to translate and job could be reviewed.
    It could confuse users and push them to delete and re-add job again and again.

  • πŸ‡©πŸ‡ͺGermany SteffenR Germany

    @andriic: Okay - than your suggestion makes sense.
    Can you give me some more information on how to reproduce the issue?
    You are writing about "Custom fields" which don't return arrays - can you give some examples?

    Thx.

  • πŸ‡ΊπŸ‡¦Ukraine andriic

    in our case we're using https://www.drupal.org/project/tablefield β†’ as a translatable field.

  • πŸ‡©πŸ‡ͺGermany SteffenR Germany

    @andriic: I've extended an existing content type with a tablefield (using latest stable 3.x release of the module) and tmgmt_deepl 2.2.9.
    Unfortunately i cannot reproduce the issue - translations are working fine - also for translatable tablefield fields.
    While translating table field content is not shown while reviewing the translation within the job. The only field which is translatable in this case is the caption field.

  • πŸ‡©πŸ‡ͺGermany SteffenR Germany
  • πŸ‡ΊπŸ‡¦Ukraine andriic

    hi @steffner!
    I've discovered what cause that issue on our side. We're using additional hook_tmgmt_job_before_request_translation() to request translations only for selected fields. And when only tablefield selected the error occurs.
    By default when requesting translation we send all fields to the translator and there's a very rare situation could happen when only tablefield in the Node will be translatable to make this error happen.

  • πŸ‡©πŸ‡ͺGermany SteffenR Germany
  • πŸ‡©πŸ‡ͺGermany SteffenR Germany
Production build 0.71.5 2024