steps to produce:
0. Clean site install of drupal 8.7 and enable content translation.
1. Add 2 languages to your site
2. Go to admin/config/regional/content-language
3. check content.
4. From the content list select article.
5. Check "hide non translatable fields on translation forms"
6. Create an article.
7. Update the article and change it's language.
8. Save.

Expected result: The language gets updated.

Actual result: Invalid translation language (und) specified. in Drupal\Core\Entity\ContentEntityBase when changing language of an entity.

more infor:

I narrowed down the problem to the "validate" method in ContentTranslationSynchronizedFieldsConstraintValidator.php,

    if ($entity->isDefaultRevision() && !$entity->isDefaultTranslationAffectedOnly()) {
      return;
    }

entity->isDefaultTranslationAffectedOnly is returning false because it has this condition:

return !empty($bundle_info[$bundle_name]['untranslatable_fields.default_translation_affected']); 

To fix my issue, I unchecked "Hide non translatable fields on translation forms" for the content types at "admin/config/regional/content-language".
Alternatively I could use this: https://www.drupal.org/node/2938191.

That said, I am not sure why setting $entity->isDefaultTranslationAffectedOnly() is relying on

$bundle_info[$bundle_name]['untranslatable_fields.default_translation_affected']

Update

I digged more into the problem and it seems that

$original_translation = $this->getOriginalTranslation($entity, $original);

calls:

$original->getTranslation($original_langcode);

But langcode is "und" and there are no translations so the exception is thrown.

This also happens when changing the language on a published node and also changing it's workflow state to draft.

Backtrace, see #26

Auf der Website ist ein unvorhergesehener Fehler aufgetreten. Bitte versuchen Sie es später nochmal.</br></br><em class="placeholder">InvalidArgumentException</em>: Invalid translation language (und) specified. in <em class="placeholder">Drupal\Core\Entity\ContentEntityBase-&gt;getTranslation()</em> (line <em class="placeholder">872</em> of <em class="placeholder">core/lib/Drupal/Core/Entity/ContentEntityBase.php</em>). <pre class="backtrace">Drupal\content_translation\Plugin\Validation\Constraint\ContentTranslationSynchronizedFieldsConstraintValidator-&gt;getOriginalTranslation(Object, Object) (Line: 111)
Drupal\content_translation\Plugin\Validation\Constraint\ContentTranslationSynchronizedFieldsConstraintValidator-&gt;validate(Object, Object) (Line: 191)
Drupal\Core\TypedData\Validation\RecursiveContextualValidator-&gt;validateConstraints(Object, &#039;000000004918feaa000000001aa08bd7&#039;, Array) (Line: 146)
Drupal\Core\TypedData\Validation\RecursiveContextualValidator-&gt;validateNode(Object, Array, 1) (Line: 99)
Drupal\Core\TypedData\Validation\RecursiveContextualValidator-&gt;validate(Object, NULL, NULL) (Line: 90)
Drupal\Core\TypedData\Validation\RecursiveValidator-&gt;validate(Object) (Line: 131)
Drupal\Core\TypedData\TypedData-&gt;validate() (Line: 488)
Drupal\Core\Entity\ContentEntityBase-&gt;validate() (Line: 192)
Drupal\Core\Entity\ContentEntityForm-&gt;validateForm(Array, Object)
call_user_func_array(Array, Array) (Line: 82)
Drupal\Core\Form\FormValidator-&gt;executeValidateHandlers(Array, Object) (Line: 275)
Drupal\Core\Form\FormValidator-&gt;doValidateForm(Array, Object, &#039;node_article_edit_form&#039;) (Line: 118)
Drupal\Core\Form\FormValidator-&gt;validateForm(&#039;node_article_edit_form&#039;, Array, Object) (Line: 575)
Drupal\Core\Form\FormBuilder-&gt;processForm(&#039;node_article_edit_form&#039;, Array, Object) (Line: 318)
Drupal\Core\Form\FormBuilder-&gt;buildForm(&#039;node_article_edit_form&#039;, Object) (Line: 93)
Drupal\Core\Controller\FormController-&gt;getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer-&gt;executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel-&gt;handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel-&gt;handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle-&gt;handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache-&gt;pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware-&gt;handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware-&gt;handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel-&gt;handle(Object, 1, 1) (Line: 693)
Drupal\Core\DrupalKernel-&gt;handle(Object) (Line: 19)
</pre>

Comments

awm created an issue. See original summary.

awm’s picture

StatusFileSize
new1012 bytes
awm’s picture

Status: Active » Needs review
jedgar1mx’s picture

I get the same error but i don't have "hide non translatable fields on translation forms" checked. I do have a paragraph entity as a field. Do you think this patch might help? or is it a completely different issue?

awm’s picture

it does not hurt to try. In your case it could be content_moderation that is causing the issue. Try disabling content moderation if that works then you might find this more helpful https://www.drupal.org/project/drupal/issues/2946402

jedgar1mx’s picture

I don't have content_moderation enable. I applied the patch but it still errors out.

I see that "varbase_bootstrap_paragraphs" module is dumped on my error, maybe that is the source. Any suggestions on what to look for?

Thanks

El sitio web encontró un error inesperado. Vuelva a intentarlo más tarde.</br></br><em class="placeholder">InvalidArgumentException</em>: Invalid translation language (es) specified. in <em class="placeholder">Drupal\Core\Entity\ContentEntityBase-&gt;getTranslation()</em> (line <em class="placeholder">872</em> of <em class="placeholder">core\lib\Drupal\Core\Entity\ContentEntityBase.php</em>). <pre class="backtrace">Twig_Template-&gt;getAttribute(Object, &#039;getTranslation&#039;, Array, &#039;method&#039;) (Line: 245)
__TwigTemplate_78154ac9ba4640db1c459abdf523e557b2ff38849bfa0615e517094d6ac7e437-&gt;doDisplay(Array, Array) (Line: 432)
Twig_Template-&gt;displayWithErrorHandling(Array, Array) (Line: 403)
Twig_Template-&gt;display(Array) (Line: 411)
Twig_Template-&gt;render(Array) (Line: 64)
twig_render_template(&#039;modules/contrib/varbase_bootstrap_paragraphs/templates/paragraph--bp-accordion.html.twig&#039;, Array) (Line: 384)
Drupal\Core\Theme\ThemeManager-&gt;render(&#039;paragraph&#039;, Array) (Line: 437)
Drupal\Core\Render\Renderer-&gt;doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer-&gt;render(Array) (Line: 490)
Drupal\Core\Template\TwigExtension-&gt;escapeFilter(Object, Array, &#039;html&#039;, NULL, 1) (Line: 57)
__TwigTemplate_48252f293d13a26bbee7dd59b064c9369ba231295e07379573ca0c4e00fcddd0-&gt;doDisplay(Array, Array) (Line: 432)
Twig_Template-&gt;displayWithErrorHandling(Array, Array) (Line: 403)
Twig_Template-&gt;display(Array) (Line: 411)
Twig_Template-&gt;render(Array) (Line: 64)
twig_render_template(&#039;modules/contrib/varbase_bootstrap_paragraphs/templates/field--entity-reference-revisions.html.twig&#039;, Array) (Line: 384)
Drupal\Core\Theme\ThemeManager-&gt;render(&#039;field&#039;, Array) (Line: 437)
Drupal\Core\Render\Renderer-&gt;doRender(Array) (Line: 450)
Drupal\Core\Render\Renderer-&gt;doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer-&gt;render(Array) (Line: 490)
Drupal\Core\Template\TwigExtension-&gt;escapeFilter(Object, Array, &#039;html&#039;, NULL, 1) (Line: 111)
__TwigTemplate_4593dbb13fd2ceca2bea08366c42e601f8fbaf2fb33ddf8f84e27814f9e87a45-&gt;doDisplay(Array, Array) (Line: 432)
Twig_Template-&gt;displayWithErrorHandling(Array, Array) (Line: 403)
Twig_Template-&gt;display(Array) (Line: 411)
Twig_Template-&gt;render(Array) (Line: 64)
twig_render_template(&#039;themes/custom/detroitmi/templates/node/node.html.twig&#039;, Array) (Line: 384)
Drupal\Core\Theme\ThemeManager-&gt;render(&#039;node&#039;, Array) (Line: 437)
Drupal\Core\Render\Renderer-&gt;doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer-&gt;render(Array, ) (Line: 226)
Drupal\Core\Render\MainContent\HtmlRenderer-&gt;Drupal\Core\Render\MainContent\{closure}() (Line: 582)
Drupal\Core\Render\Renderer-&gt;executeInRenderContext(Object, Object) (Line: 227)
Drupal\Core\Render\MainContent\HtmlRenderer-&gt;prepare(Array, Object, Object) (Line: 117)
Drupal\Core\Render\MainContent\HtmlRenderer-&gt;renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber-&gt;onViewRenderArray(Object, &#039;kernel.view&#039;, Object)
call_user_func(Array, Object, &#039;kernel.view&#039;, Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher-&gt;dispatch(&#039;kernel.view&#039;, Object) (Line: 156)
Symfony\Component\HttpKernel\HttpKernel-&gt;handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel-&gt;handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle-&gt;handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache-&gt;pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache-&gt;handle(Object, 1, 1) (Line: 49)
Asm89\Stack\Cors-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware-&gt;handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware-&gt;handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel-&gt;handle(Object, 1, 1) (Line: 666)
Drupal\Core\DrupalKernel-&gt;handle(Object) (Line: 19)
</pre>
awm’s picture

go to admin/config/regional/content-language and check paragraphs and see if you have "Hide non translatable fields on translation forms" for paragraphs entity type. The patch above probably does not cover all cases with entities provided by contrib module. It may be a paragraphs issue. You can probably use this

/**
 * Implements hook_entity_bundle_info_alter().
 */
function my_module_entity_bundle_info_alter(&$bundles) {
// replace node with paragraphs and correct bundle.. 
  $bundles['node']['article']['untranslatable_fields.default_translation_affected'] = TRUE;
}
jedgar1mx’s picture

I will look into it, thank you so much for the help.

jedgar1mx’s picture

It seems that every time I add a translation the default (en) language gets change.

The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">LogicException</em>: The default translation flag cannot be changed (bn). in <em class="placeholder">Drupal\Core\Entity\ContentEntityBase-&gt;onChange()</em> (line <em class="placeholder">831</em> of <em class="placeholder">core\lib\Drupal\Core\Entity\ContentEntityBase.php</em>).

awm’s picture

After testing, it seems this issue is still not completely resolved with the patch above.THe issue reoccure when content moderation is enabled and editorial workflow is set for content types. When trying to change the language on a node and changing the moderation state to draft, it fails with the same error:

The website encountered an unexpected error. Please try again later.InvalidArgumentException: Invalid translation language (und) specified. in Drupal\Core\Entity\ContentEntityBase->getTranslation() (line 872 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).

perhaps this should not be allowed? i.e we should not allow users to change the language on a draft content that has a published content in a different language.

awm’s picture

Issue tags: +content translation
awm’s picture

Issue summary: View changes
awm’s picture

Pascal-’s picture

#14 seems to work for me

lpeabody’s picture

Status: Needs review » Reviewed & tested by the community

I had another issue:

1) With content translation and content moderation enabled, edit a node that is set to a specific language.
2) In the language selector, set to Not specified and save the node as published.
3) Get the error message in the title.

After applying this patch, I no longer receive that error message. I also reviewed https://www.drupal.org/project/drupal/issues/2946402 since I had content moderation enabled, and I was operating on 8.6.6, so that issue did not apply to my case since it was already change in core. As far as I can tell things are working as expected now. Going to set to RTBC since Pascal says it's working for him and it's also working for me.

EDIT: Just kidding, it's still happening. At one point it seemed to resolve itself after having applied the patch but then it just started happening again on different content.

sam152’s picture

Status: Reviewed & tested by the community » Needs work

I don't think this is committable without tests.

sam152’s picture

I can confirm the steps in the issue summary reproduce this without content moderation being enabled.

sam152’s picture

StatusFileSize
new1016 bytes
new2.26 KB

I think this is fixable while staying true to the intentions of the validator and without requiring exceptions and error handling. I was also able to reproduce this in a test as well.

rajeevk’s picture

Status: Needs work » Needs review

The last submitted patch, 19: 2995655-19_TEST-ONLY.patch, failed testing. View results

lpeabody’s picture

I'm linking what may be a related issue, given it's the same error with similar circumstances, only also involving entity_reference_revisions as well as content_moderation. The error message reported in that issue is the same being reported here. Link to issue with call stack https://www.drupal.org/project/entity_reference_revisions/issues/3024588 (my call stack is identical to that one).

Unfortunately with patch from #19 applied, I still receive the error Invalid translation language (und) specified..

Two additional observations:

1) On a Drupal 8.6 install, with content moderation enabled for a content type (that has no ERR fields, just three simple text fields), with "hide non translatable fields" enabled for it, I am able to freely switch the languages of the node without error. So I am not encountering the issue error, even though I think I'm running the same setup (minus running on 8.7).

2) On a similar setup, when editing a content type that has ERR fields, I am able to freely switch the language of the node to other enabled languages without error. However, when setting the node to Not specified or Not applicable, that triggers the issue error (replacing und with zxx in the case of Not applicable).

Posting this here because I'm not sure who the culprit is, CM or ERR. Just trying to provide as much information as possible. I'll leave this as Needs review since I'm only encountering this problem on content types that host ERR fields.

lpeabody’s picture

Status: Needs work » Needs review
sam152’s picture

Yeah, I think NR is correct here unless you can still reproduce the error with the steps listed in the issue summary. I think the call-stack in your related issue is quite different to this issue, here we're attempting to load a particular original revision and translation for the purposes of validation, over there it seems to actually be during the rendering or saving of a form, hard to tell.

It seems this issue is becoming a bit of a catch-all for every issue that surfaces as Invalid translation language (und) specified..

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

geek-merlin’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

I can confirm this issue. FTR, i copied my stacktrace to the IS.

@awm: Chapeau for excellent debugging / analysis, @Sam152: Well documented code and test!

I can canfirm the patch fixes the issue for me.

Code review:
* The patch does what the analysis from the IS says and fixes a missed codepath of cited API addition.
* The test is trivial and shows the code does what it announces.

So i'd say RTBC.

sam152’s picture

Thanks for the review @axel.rutz.

plach’s picture

This looks great, very nice catch and troubleshooting!

  • plach committed adda2c8 on 8.8.x
    Issue #2995655 by awm, Sam152, jedgar1mx, lpeabody, axel.rutz: Invalid...

  • plach committed 6b61922 on 8.7.x
    Issue #2995655 by awm, Sam152, jedgar1mx, lpeabody, axel.rutz: Invalid...
plach’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -content translation

Committed adda2c8, pushed to 8.8.x, and backported to 8.7.x. Thanks!

Status: Fixed » Closed (fixed)

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

arjak-mondal’s picture

StatusFileSize
new3.11 KB

Patch for drupal 11.2.x: