Problem/Motivation
Getting the below HTTP 500 fatal error on trying to add a translation of an 'draft' English node, Which was earlier 'published' with language 'not defined'.
InvalidArgumentException: Invalid translation language (und) specified. in Drupal\Core\Entity\ContentEntityBase->addTranslation() (line 955 of /core/lib/Drupal/Core/Entity/ContentEntityBase.php).
Steps to reproduce
- Install Vanilla Drupal's Standard Installation Profile with
English as site language.(Note: I faced this error on 8.x and 9.x. So Install any version you want.)
- Log in as an admin and enable the following modules
- Configuration Translation
- Content Translation
- Interface Translation
- Language
- Content Moderation
- Workflows
Go to the path /admin/config/regional/language/add & add the French language to your site.
Configure URL language detection method by visiting the path /admin/config/regional/language/detection/url such that it has below values:
- Part of the URL that determines language:
Path Prefix should be selected
- Path Prefix Configuration:
en in English textfield, And fr in French textfield.
Create content type, Allow content of this content type to be translatable. And show the 'Language' dropdown on this content's add/edit page.
Make this content type follow the default editorial workflow by visiting the path /admin/config/workflow/workflows/manage/editorial
Create a node of this content type, Such that it's published with language as Not Specified.
Now, Edit the newly created node, Change its language to English and save it as a draft.
On the node view page, You will see the Translate tab. Click on it.
Try adding the french translation of this node. And you will see the fatal error shown in attached screenshot.
Note: When the content type does not follow the 'editorial' workflow, Then you won't see the fatal error
Proposed resolution
- Ideally, We should not allow language switching of an existing node.
- But in the real world content editors tend to do language switching. Hence If we are allowing language switching, Then we should not get an fatal error for adding translations.
Remaining tasks
"None at the time of creating this issue."
User interface changes
"None at the time of creating this issue."
API changes
"None at the time of creating this issue."
Data model changes
"None at the time of creating this issue."
Release notes snippet
"None at the time of creating this issue."
Comments
Comment #2
kunalkursija commentedChanging version to 9.2.x.
Note: This error exists on both 8.x & 9.x
Comment #3
sam152 commented