Problem/Motivation
This commit broke the compatibility with custom entities which have translation disabled.
This issue was fixed here #2698239: Multilingual workflow bugs but it does not have test converage for this.

Solution
Add test coverage for entities with unspecified language.

Comments

alexej_d created an issue. See original summary.

alexej_d’s picture

Title: Follow-up to #2513226: Test for untranslatable entities before attempt to create a new translation » A fatal error occurred: Invalid translation language (und) specified.
hctom’s picture

I can confirm this bug. I just tried to add an entity reference field to a paragraphs type that references a Block entity, but it is impossible to add this paragraph due to the above stated errors.

I will also have a look at the code, but perhaps one of the maintainers has an easy fix right out of the box? ;)

farald’s picture

Hey, just confirmed this.

  • Paragraphs field on untranslatable node, uses empty Pragraphs entity.
  • When trying to add anything, Console reports Internal server error.
  • In the dblog, I find:

InvalidArgumentException: Invalid translation language (zxx) specified. i Drupal\Core\Entity\ContentEntityBase->addTranslation() (linje 826 i /home/foo/core/lib/Drupal/Core/Entity/ContentEntityBase.php).

farald’s picture

Update: Setting the default node language is a confirmed workaround, though I'd love to not having to enable that :)

jeroen.b’s picture

@farald, you can also use this workaround:

function HOOK_paragraph_create(\Drupal\paragraphs\Entity\Paragraph $entity) {
  $entity->set('langcode', Language::LANGCODE_NOT_SPECIFIED);
}

You might want to do some extra checks inside the hook to get the correct langcode if you don't want LANGCODE_NOT_SPECIFIED.

ksavoie’s picture

Getting this same error except on an site that is NOT multilingual.

Content of site was migrated from D7.
With the migration came a content type "Article".
Added a 2 text field Paragraph to this content type.
New "Articles", I can successfully add in Paragraphs with expected behavior.
Existing "Articles" (ones that came over in the migration), I receive this error in console when I press the add Paragraph button.

AjaxError: 
An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /mySubdirectory/node/669/edit?destination=/mySubdirectory/admin/content&ajax_form=1
StatusText: Internal Server Error
ResponseText: {"message":"A fatal error occurred: Invalid translation language (und) specified."}
ksavoie’s picture

jeroen.b (#6)
I attempted to use your workaround however I am still receiving the error when editing nodes that were migrated from D7. New nodes of the same type have no issue with 'Paragraphs'.
I also tried 'LANGCODE_DEFAULT' as the language type as my site is not multilingual.
Just to verify your workaround is placed in xzy.theme file correct?

Any additional insight to get this module to work greatly appreciated!
Thanks.

jeroen.b’s picture

@ksavoie, no, the code should be placed in a .module file.
HOOK in the function name should be replaced with the module name.

ksavoie’s picture

jeroen.b #6 works! Thank you!
The only addition I would add for the readers is that in your module make sure to include at the top

use Drupal\Core\Language\Language;

so your module has access to the 'Language' class.

Luxian’s picture

StatusFileSize
new1.01 KB

I managed to fix this issue with the following patch. Not sure if it's the right approach. #6 didn't work for me (got the same error).

I was inspired by node module, which adds the source language as a field to add translation form and probably sets it on submit.

Luxian’s picture

Status: Active » Needs review
ksavoie’s picture

Well I spoke too soon. #6 didn't fully correct my paragraphs in my application and @Luxian's patch didn't work either.

I have some info that may shed some light.
In my install the majority of content came from a D7 migration. In reviewing different nodes the 'langcode' values are a mix between 'en' and 'und'. The D8 site is not configured as multilingual (Language not installed).

After some tinkering it appears this issue may revolve around this.
I enabled the Language module (with only English) and enabled language selection for content type 'page' (for which I have a Paragraph).
It appears that Paragraph fails when the the nodes langcode does not match Paragraphs default language.
When I change the nodes language to Paragraphs default it works.
b.t.w I removed both #6 and #11 fixes.

To work around the problem in my implementation, I enabled language selection on the Paragraph I created and the node types that have it implemented (/admin/config/regional/content-language) and set both Default Languages to "- Not Specified -" (which is what the majority of my nodes are). On nodes that come up as English I just update to "- Not Specified -" and Paragraphs works.

I hope this info leads to a fix!

miro_dietiker’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Promoting for attention.
Still, we need test coverage for the issues identified.

berdir’s picture

Priority: Normal » Critical

Seems like a release blocking bug?

ksavoie’s picture

Is there anything I can provide that would assist in debug?

therealssj’s picture

StatusFileSize
new1.16 KB

Here is a patch that works for me.
@ksavoie in your comment #13 it works because addTranslations is only called if your target langcode and default langcode are different so when you target to default as mentioned by you the content loads.

therealssj’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 17: 2591171-17.patch, failed testing.

The last submitted patch, 17: 2591171-17.patch, failed testing.

The last submitted patch, 17: 2591171-17.patch, failed testing.

webflo’s picture

Status: Needs work » Needs review
StatusFileSize
new2.27 KB

The patch in #11 did not work for me. The paragraph widget assumes that the parent entity is always translatable and tries to derive the paragraph language from its host entity. This does not work with ContentEntityBase. ContentEntityBase does not allow translations for locked languages. I tried to derive the paragraph language from the current language context if the parent entity is not translatable.

webflo’s picture

The patch in #11 did not work for me. The paragraph widget assumes that the parent entity is always translatable and tries to derive the paragraph language from its host entity. This does not work with ContentEntityBase. ContentEntityBase does not allow translations for locked languages. I tried to derive the paragraph language from the current language context if the parent entity is not translatable.

  1. +++ b/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php
    @@ -731,7 +731,7 @@ class InlineParagraphsWidget extends WidgetBase {
           // Hide the button when translating.
    

    We should move the comment to addMoreAccess

  2. +++ b/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php
    @@ -838,6 +838,14 @@ class InlineParagraphsWidget extends WidgetBase {
    +    // The from and the parent entity have a locked language
    

    Typo. The form ..

therealssj’s picture

StatusFileSize
new3.09 KB
new2.83 KB

The patch in #22 fails if we try to add an untranslatable paragraph on a new node.

Now getting the paragraph language from current language if an untranslatable paragraph is added.

Also added test coverage for this.

Status: Needs review » Needs work

The last submitted patch, 24: 2591171-24.patch, failed testing.

The last submitted patch, 24: 2591171-24.patch, failed testing.

The last submitted patch, 24: 2591171-24.patch, failed testing.

therealssj’s picture

StatusFileSize
new3.13 KB
new2.86 KB

Forgot to check whether langcode was set.

therealssj’s picture

Status: Needs work » Needs review
tduong’s picture

Opened a "multilingual workflow bugs only meta issue" #2698239: Multilingual workflow bugs for a "general" discussion for these kind of bugs.

miro_dietiker’s picture

Status: Needs review » Postponed

This needs a recheck after the general multilingual fix.

miro_dietiker’s picture

duplicate.

johnchque’s picture

Status: Postponed » Needs review
StatusFileSize
new800 bytes

It seems it has been already fixed in the Multilingual issue, but just to be sure, added tests taken from @tduong patch. Also tested manually, seems to be working fine now. :')

berdir’s picture

Title: A fatal error occurred: Invalid translation language (und) specified. » Add test coverage for entities with unspecified language
Category: Bug report » Task
Priority: Critical » Normal
Status: Needs review » Needs work
Issue tags: -Needs tests +Needs issue summary update
+++ b/src/Tests/ParagraphsTranslationTest.php
@@ -191,6 +191,12 @@ class ParagraphsTranslationTest extends WebTestBase {
+    $edit = array('langcode[0][value]' => 'und');

This should use the constant instead.

Changing to a normal task and updating title, issue summary should also be updated.

therealssj’s picture

StatusFileSize
new1006 bytes

Patch fix according to #34

therealssj’s picture

Issue summary: View changes

There we go.
I hope this is good enough :)

tduong’s picture

Status: Needs work » Needs review

Good! Set to needs review for testbot test.

Status: Needs review » Needs work

The last submitted patch, 35: 2591171-35.patch, failed testing.

The last submitted patch, 35: 2591171-35.patch, failed testing.

The last submitted patch, 35: 2591171-35.patch, failed testing.

tduong’s picture

Status: Needs work » Needs review
StatusFileSize
new1.09 KB

Rerolled.

johnchque’s picture

Status: Needs review » Reviewed & tested by the community

Think looks good enough.

miro_dietiker’s picture

Status: Reviewed & tested by the community » Fixed

Thx, committed. :-)

  • miro_dietiker committed 990082a on 8.x-1.x authored by tduong
    Issue #2591171 by therealssj, tduong, yongt9412: Add test coverage for...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.