Specifies when the error occurs (during translation)

Created on 20 March 2025, 3 months ago

Problem/Motivation

When attempting to create a translation (specifically an English translation) for content that uses Layout Builder, the process fails with the following error:

InvalidArgumentException: The specified translation (en) cannot be removed. in Drupal\Core\Entity\ContentEntityBase->removeTranslation() (line 1023 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).

This error occurs in the Layout Builder Asymmetric Translation (layout_builder_at) module when it attempts to remove a translation that cannot be removed - typically the default language translation during the block replication process.

Steps to reproduce

  1. Install and enable Layout Builder Asymmetric Translation module
  2. Configure a content type to use Layout Builder overrides
  3. Add Layout Builder sections and blocks to a piece of content
  4. Configure the content type to be translatable
  5. Try to add a translation for the content (typically an English translation if English is the default language)

Proposed resolution

Modify the LayoutBuilderCopyWidget->extractFormValues() method to gracefully handle cases where a translation cannot be removed:

  1. Add try-catch blocks around calls to removeTranslation() to catch the InvalidArgumentException
  2. Add additional checks to prevent attempting to remove the default language translation
  3. Log the exception details instead of allowing the exception to bubble up and break the translation process
  4. Continue with the translation process even if certain translations cannot be removed

This ensures the translation process can continue without errors while maintaining the core functionality of the module.

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇩🇪Germany solimanharkas Hamburg

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024