I completed a content migration from a Drupal 7 site to a new Drupal 8 site using the upgrade GUI. Migration was pretty painless. Months later I enabled core content moderation and turned content moderation on for my custom content type "Collection Item". With content moderation on, I was no longer able to save my Collection Item nodes without seeing: The website encountered an unexpected error. Please try again later.
Two errors register, as follows:
Drupal\Core\Entity\EntityStorageException: Invalid translation language (und) specified. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 770 of /Applications/MAMP/htdocs/project/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
And...
InvalidArgumentException: Invalid translation language (und) specified. in Drupal\Core\Entity\ContentEntityBase->addTranslation() (line 823 of /Applications/MAMP/htdocs/project/core/lib/Drupal/Core/Entity/ContentEntityBase.php).
I then enable the devel module and visit /devel/php where I load my node to inspect the language settings:
$node = node_load(3743);
dpm($node->language());
And I see that language is "und":
stdClass Object
(
[__CLASS__] => Drupal\Core\Language\Language
[defaultValues] => Array
(
[id] => en
[name] => English
[direction] => ltr
[weight] => 0
[locked] =>
)
[name] => Not specified
[id] => und
[direction] => ltr
[weight] => 2
[locked] => 1
)
This appears to be legacy data that came over from Drupal 7. The language of 'und' prevents me from saving / updating the node when content moderation has been enabled for the content type. If I disable content moderation, I'm able to save the node as normal.
If I manually change the node's langcode to 'en' via some php code at devel/php, I'm able to save the node with content moderation enabled. Also you can see the language setting has changed appropriately:
$node = node_load(3743);
$node->langcode = 'en';
$node->save();
dpm($node->language());
stdClass Object
(
[__CLASS__] => Drupal\Core\Language\Language
[defaultValues] => Array
(
[id] => en
[name] => English
[direction] => ltr
[weight] => 0
[locked] =>
)
[name] => English
[id] => en
[direction] => ltr
[weight] => 0
[locked] =>
)
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | excluding-translate-if-language-is-locked-2877481-1.patch | 2.61 KB | dmitri.daranuta |
Comments
Comment #2
timmillwoodComment #3
dmitri.daranuta commentedComment #4
dmitri.daranuta commentedComment #5
dmitri.daranuta commentedComment #6
timmillwoodThanks, nice start.
We really need tests for this though.
LanguageManager needs to be injected.
Comment #7
tacituseu commentedI think this should be combined with solution from #2856917: Moderating an entity that uses a special language (e.g. LANGCODE_NOT_SPECIFIED) throws exception, that is create it with the same
langcodeas entity in the first place, otherwise there is a mismatch, entity is in'und'and the content_moderation_state in site's default ('en') might cause problems with views later.Comment #8
amateescu commentedLet's fix this in #2856917: Moderating an entity that uses a special language (e.g. LANGCODE_NOT_SPECIFIED) throws exception, it's exactly the same issue.