Trying to edit certain nodes I am getting:
The website encountered an unexpected error. Please try again later.
InvalidArgumentException: Invalid translation language (und) specified. in Drupal\Core\Entity\ContentEntityBase->addTranslation() (line 953 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).
entity_reference_revisions_entity_revision_create(Object, Object, NULL)
call_user_func_array('entity_reference_revisions_entity_revision_create', Array) (Line: 403)
Drupal\Core\Extension\ModuleHandler->invokeAll('entity_revision_create', Array) (Line: 327)
Drupal\Core\Entity\ContentEntityStorageBase->createRevision(Object, ) (Line: 294)
Drupal\content_moderation\EntityTypeInfo->entityPrepareForm(Object, 'edit', Object) (Line: 136)
content_moderation_entity_prepare_form(Object, 'edit', Object)
call_user_func_array('content_moderation_entity_prepare_form', Array) (Line: 408)
Drupal\Core\Entity\EntityForm->prepareInvokeAll('entity_prepare_form', Object) (Line: 139)
Drupal\Core\Entity\EntityForm->init(Object) (Line: 291)
Drupal\Core\Entity\ContentEntityForm->init(Object) (Line: 107)
Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 518)
Drupal\Core\Form\FormBuilder->retrieveForm('node_services_edit_form', Object) (Line: 275)
Drupal\Core\Form\FormBuilder->buildForm('node_services_edit_form', Object) (Line: 93)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 41)
Drupal\jsonapi\StackMiddleware\FormatSetter->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 669)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
It seems odd that entity_reference_revisions_entity_revision_create is being called by simply loading node/xx/edit
Seems related to comment 83 of #2961399: Support parallel translation forward revisions on untranslatable fields.
Comments
Comment #2
alberto56 commentedHere is a patch which, at least, does not result in a fatal error. See screenshot.
Comment #3
alberto56 commentedIn my case field_resources is a paragraph:
Calling dpm(\Drupal\paragraphs\Entity\Paragraph::load(2236)); works fine, so I'm not sure why this is happening. The revision ID seems to exist, too, so I'm not sure what's going on:
In any event, perhaps the try/catch block is better because it prevents a fatal error when editing a page.
Saving the node, in my example, then coming back to the edit page, resulted in the error message disappearing.
It should be noted that this particular content was migrated from a Drupal 7 site so there might be something strange with the data.
Comment #4
lpeabody commentedI'm able to reproduce this error like so:
1) Edit a node that has a language assignment.
2) Set node language to Not specified.
3) Save the node.
4) Edit the node, get the error message in the main summary above.
Comment #5
lpeabody commentedAdding what could be a related issue. Though, the patch from that issue does not seem to solve our problem.
Comment #6
lpeabody commentedSome rapid feedback I can give from some more testing I've just done...
1) If I make sure that every paragraph and nested paragraphs are expanded in the node edit form, and I set the node language to Not specified (und), and save I can then edit the node again without error.
2) If I disable content moderation for that content type I can save/edit the node again in any combination of languages (including und).
So I think additional work needs to be done to make ERR and content moderation play nicely together.
I'll have to revisit this over the weekend or early next week to provide more information as I need to get this working for a client.
Comment #7
dieuweI have the same issue here, and also with migrated data from Drupal 7. The patch "fixes" the fatal error, but doesn't do much beyond that.
When I view the node, I can see the rendered paragraph, but when I edit it (using the patch) I now see the following error and then there are no paragraph loaded in the entity reference field:
entity_reference_revisions_entity_revision_create had trouble updating delta 0 of field_co_owners; moving on.It's a starting point for looking into exactly WHY some of these migrated entities are broken and what we can do to fix them. I'll let you know when I find out what it is.
Comment #8
dieuweHere's some info as to how I managed to work around the problem:
What was actually happening is that the node revision was send to 'und' while the paragraph revision was set to 'en' and so no matching translation could be generated.
A more permanent and safe solution might be to convert all content to either 'und' or 'en', but I am not sure which should be preferable or how this might interfere with the content moderation module.
You'll run unto this problem if you have migrated content with the langcode 'und' and then some paragraphs that have been assigned the 'en' langcode (in my case I think these were generated separately, not part of the original migration).
Perhaps someone could suggest some kind of update hook that can be used to normalise all content to the correct langcode?
Comment #9
keboca commentedI can confirm the patch https://www.drupal.org/project/entity_reference_revisions/issues/3024588... works charming in my case. Thanks folks!
Comment #10
keboca commented@dieuwe I agree with your comments. Actually there's a blog which's pointing to same issue,
https://atendesigngroup.com/blog/fixing-invalid-translations-drupal-8-co...
I tried to create an hook_update_N in order to execute `$node->set('langcode', $langcode);` into all nodes with that bug. However the method invokes `addTranslation` which trigger the same issue, then no luck. Reason why I came with this query inside a hook_update_N:
It update manually all nodes with UND language code defined. Even tho, the messages provided by the patch was still there:
As soon as I update any module with those messages Drupal does its things, then the message is vanish and it won't longer appear.
I would say it's good enough, nonetheless if you want to go further, then you may create another hook_update_N to load all nodes and save them again, surely it will solve everything at once.
Be aware to avoid any timeout while updating all your content.
Comment #11
alberto56 commentedThe patch in #2 no longer applies to 8.x-1.7 released 5 October 2019.
Here is the same patch which applies to the latest version of the code.
Comment #12
davo20019 commentedI had the same problem, and it was happening because of a file field that one of my paragraphs had, was not checked as translatable at /admin/config/regional/content-language. Only the Alt and Title fields of the file field were checked as translatable.
Comment #13
fredonia_webteam commentedWe have the same problem. This error is happening when content_moderation module is configured for node content types. It seems the error is only happening on pages that contain paragraphs. Language is not enabled. The paragraphs fields are being migrated from Drupal 7 come over with the language en.
Comment #14
flodevelop commentedSame here @davo2019.
Caused by a file field non translatable inside a paragraph.
With Content Moderation module enable on the parent node content type.
Comment #15
lisp commentedSame "problem" as mentioned at #12
Drupal version: 8.9.1
Error message: InvalidArgumentException: Invalid translation language (und) specified. in Drupal\Core\Entity\ContentEntityBase->getTranslation() (line 873 of /var/www/html/drupal/...web/core/lib/Drupal/Core/Entity/ContentEntityBase.php).
Checking image checkbox in /admin/config/regional/content-language in the paragraph section did solve the problem for me.
Comment #16
vistree commentedHi, I have exactly the same problem!! Using content moderation with paragraphs in a multi language environment. We need to allow users to choose the language option "Language: Not specified". Problems start, when users try to change afterwards to a different language option (like EN).
On content type "basic page" I have an "entity reference revsion" field which links to a paragraph (field_section). Within this paragraph, I have an additonal "entity reference revsion" field, which again links a paragraph (field_section_content).
From what I have seen in all documentations and even the interface tells me NOT to translate the field in the sub-paragraph (field_section_content). Using patch from #11 I can see the error pointing to field_section_content.
As a test I enabled translation for this field - and the error has gone away (and existing sections are again displayed inside node edit form).
But, can I now keep the translation of field "field_section_content" on or will it break my site because of "https://www.drupal.org/node/2735121"?? Any idea on how to solve this? By the way: we need the
Comment #17
sic commentedwe are also having this problem, out of the blue. adding an english translation (from german for instance) does run into the error. adding other translations, lets say from german to french, works just fine. 8.9.1
Comment #18
juampynr commentedIn my case this was caused because I had a custom paragraphs migration that was setting the langcode to en, while the node migration that referenced such paragraph was using und.
Changing the custom migration to use und as the default langcode fixed it.
Comment #19
vistree commentedWe don't use migrated content. Problem is also for fresh content + paragraphs add directly in the new nodes.
Comment #20
pratik_kambleI have migrated the content from D7 to D8. And then turn on the content moderation module. Post to that I ran into this problem. Below code works for me.
Comment #21
dorficus commented@pratik_kamble: did you make a patch for this? the current one is not applying and I'm running into this issue as well. I don't want to duplicate work if you've already put in the effort. Also, it couldn't hurt to contribute the patch back.
Comment #22
gsa commentedHere's the patch using the code from #20.
Works fine in my case.
Comment #23
jimkeller commentedWe were still seeing issues with the patch in #20; attached is an updated patch that doesn't try to addTranslation on the default language, and also won't try to getTranslation unless it exists.
I'm not convinced this fix will actually suffice for multilingual sites - it seems like we're just juggling "und" and the default language code ("en" for me) to work around the exceptions. This is fine for my case since I only have one language but I feel like a more substantial fix is necessary here.
Comment #24
Lal_#22 will come down with an error, when you want convert a entity in 'und' to 'en' (Drupal doesn't allow that) and thats why the check is necessary... IMO #23 is the best fix for this... Also tested on my local and it works perfectly... Thanks!!
Comment #25
nironan commentedWe have #23 installed on a multilingual website and can confirm that we didn't get any side effect so far
Comment #26
dioni commentedI can confirm the same, multilingual website and working with #23 installed
Comment #27
tmwagner commentedConfirmed: Had exactly the same issue as described. Oddly, it was not happening until we updated core to 8.9.16.
Patch solved the problem
Comment #28
attisanAdded usage of
\Drupal\Core\Language\LanguageInterfaceconstants instead of using'und'string and added a check againstLanguageInterface::LANGCODE_NOT_APPLICABLE(see #2961399: Support parallel translation forward revisions on untranslatable fields).Comment #29
vistree commentedWe have the same problem with Drupal 9.3.8 and 9.3.9. Pathes from #23 and #28 both apply - but we still get the error. Content moderation is NOT in place, but the page is multilingual
Comment #30
mkindred commentedI ran into this error on Drupal 9.3.9 site (not multilingual) with content moderation and paragraphs migrated from D7. Patch #23 worked so far.
Comment #33
liam morlandI just created a merge request with patches 22, 23, and 28, so the interdiffs can easily be seen.
Comment #34
steinmb commentedI assume it is coming from here. Sorry, have not tested the merge request.
Comment #35
steinmb commentedTested MR on top of latest dev and D9.4.4 - I still got the error during a node migration from D7 field_collection to paragraph. Target site only have English lang. installed. though the language module is intalled.
Comment #36
adriancotter commentedI tested the MR on with Core 9.4.4 and am getting the same error. Although I was not using the latest dev.
For me, These errors are happening for node migrations. No language module installed. These errors were not happening last time I did the migration a couple of weeks ago. I'm not sure the exact change in between -- something on D7? or I think I did update D9 Core in there. It certainly wasn't the entity_reference_revision module though.
[error] Invalid translation language (und) specified. (/web/core/lib/Drupal/Core/Entity/ContentEntityBase.php:956)
I assume that it should never be getting to the addTranslation method here in ContentEntityBase, since by definition the language of my content is correctly 'und'?
I'll try and play around with the code this coming week.
## UPDATE ### Turns out this error -- for me -- was a complete red herring. When I started testing more content types -- I got some duplicate ID errors instead of the translation language error... and then remembered that I had a process creating nodes of another sort.... possibly ones that didn't have revisions turned on? Either way -- I'm not entirely sure why it ended up with the translation error -- but the problem was a node existing in a place it shouldn't...
Comment #37
steinmb commentedRef. #34 and #35 - My problem turned out to be similar to #36. In other words you can safely ignore my reports. Colliding id between D9 and 7 lead to migration tried to upgrade wrong node bundle during migration.
Comment #40
dieterholvoet commentedRebase was a bit too complex so I merged 8.x-1.x in the issue fork.
Comment #41
damienmckennaRerolled.
Comment #42
anup.singh commented#41 worked for me.
Comment #43
dieterholvoet commentedThe latest state of the MR doesn't fix the issue for me. When saving a translation, I get 'Non-translatable field elements can only be changed when updating the current revision.'. This issue is not present when I apply the patch from #41.
In both cases I do have another issue: I still get the 'Invalid translation language (und) specified' error, unless I add the following snippet, in that case everything works as it should.
I have seen this fix/workaround be necessary for multiple other modules dealing with translations, so I'll add it here as well.
It's probably an issue with content_translation, but I haven't been able to figure that out.
Comment #44
berdirThis seems to require a manual rebase.
Comment #46
firewaller commented#41 works for me
Comment #48
rupertj commented#41 no longer applies. I've updated the issue fork with the code from 8.x-1.x. It's mergeable again and I'm successfully using the MR diff as a patch against 8.x-1.13.
There's a test failure in the pipeline, but it seems to be unrelated to the change in this MR?
Comment #49
drupov commentedHey @rupertj - thanks for the update!
Can you post the link to the diff here also?
Comment #50
rupertj commented@drupov - Click the link under the issue summary that says "changes". Then there's a link under the "Code" button in the top right to the changes in the MR as a diff. You can do that for any MR in GitLab.
Comment #51
berdirTest coverage helps issues like this to get committed, but I also don't want to hold this up forever as this clearly affects quite a few people.
Did my best with the contribution credits, lots of people in this issue. Merging...
Comment #55
anybodyGREAT work, thank you berdir! Just ran into this and upgrading to the latest version fixed it. Hero of the day!! :)