XLIFF import crashes on source-language mismatch.

Created on 3 April 2017, over 8 years ago
Updated 8 September 2025, 6 days ago

To reproduce:

- Create a job
- Import an XLIFF with the wrong source language

Result:

- The following job message is created:

      $job->addMessage('The imported file target language @file_language does not match the job target language @job_language.', array(
        '@file_language' => empty($xml->file['target-language']) ? t('none') : $xml->file['target-language'],
        '@job_language' => $job->target_language,
      ), 'error');

However, $xml->file['target-language'] is a SimpleXMLElement instance, not a string. When the message gets serialized, the following error results:

Drupal\Core\Entity\EntityStorageException: Serialization of 'SimpleXMLElement' is not allowed in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 770 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
Drupal\Core\Entity\Sql\SqlContentEntityStorage->mapToStorageRecord(Object, 'tmgmt_message') (Line: 806)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->doSaveFieldItems(Object) (Line: 263)
Drupal\Core\Entity\ContentEntityStorageBase->doSave(NULL, Object) (Line: 392)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 761)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object) (Line: 364)
Drupal\Core\Entity\Entity->save() (Line: 346)
Drupal\tmgmt\Entity\Job->addMessage(Object, Array, 'error') (Line: 262)

Suggested solution:

Cast this value to string when including it as a message variable.

🐛 Bug report
Status

Needs review

Version

1.0

Component

Translator: File

Created by

🇨🇭Switzerland cburschka

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • 🇧🇬Bulgaria pfrenssen Sofia

    The fix is incomplete. It is not sufficient to only cast $xml->file['source-language'] to a string when creating the error message. In the preceding if statement we also need to compare the string value.

  • Pipeline finished with Failed
    6 days ago
    Total: 294s
    #593249
  • 🇧🇬Bulgaria pfrenssen Sofia

    Moved patch #11 to a MR.

    I was wrong in comment #15, the original code does a loose comparison and it works as expected when comparing a string with a SimpleXMLElement object. But I still decided to keep this modest improvement in the MR ;)

Production build 0.71.5 2024