@FeyP reported the original (related) issue which happens in core but the problematic portion of the code is identical in token and the issue also happen here. I've ported the patch here based on his work in the related issue.

When changing the language of an existing node to a pseudo language I get the following error:

InvalidArgumentException</em>: Invalid translation language (und) specified. in <em class="placeholder">Drupal\Core\Entity\ContentEntityBase-&gt;addTranslation()</em> (line <em class="placeholder">947</em> of <em class="placeholder">core/lib/Drupal/Core/Entity/ContentEntityBase.php</em>). <pre class="backtrace">token_node_menu_link_submit(&#039;node&#039;, Object, Array, Object)
call_user_func_array(&#039;token_node_menu_link_submit&#039;, Array) (Line: 299)
...

Here is the introduction of the original report:

Changing the language of a translatable node with a translatable menu link from a "real" language (e.g. en) to a "pseudo" language (und or zxx) will result in an invalid argument exception: Invalid translation language (und) specified. or Invalid translation language (zxx) specified. respectively.

Issue fork token-2986581

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

idflood created an issue. See original summary.

idflood’s picture

idflood’s picture

Status: Active » Needs review
berdir’s picture

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

Nice catch. Can we extend \Drupal\token\Tests\TokenMenuTest so it covers this scenario as well?

malte.koelle’s picture

I created a test similar to the test in the issue #2904899.
First I create a node with the Language English and try to access the node.
Then I create a menu link and change the language to "not specified" and again try to access the page.

I would be glad if someone can review my test.

Status: Needs review » Needs work

The last submitted patch, 5: token-exception-when-changing-language-2986581-5.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

malte.koelle’s picture

I moved the setUp part directly to my test method, since it creates a node with a specific id and it cannot do it twice.
Hopefully the test works now. :)

malte.koelle’s picture

Status: Needs work » Needs review
anybody’s picture

Status: Needs review » Needs work

This needs a reroll against latest version.

anybody’s picture

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

@Berdir: Would you like to review this?
I rerolled #7 as MR!31 without any additional changes.
Removing "Needs tests" as tests were added in #7. Credits to malte.koelle! :)

anybody’s picture

Here's the diff from MR!31 if anyone needs it locked. Should also work with 8.x-1.10+!

RTBC+1 from my side, we were running into this issue and with the patch applied it's fixed!

idflood’s picture

Here is a reroll of patch #13. I can push a new branch with just this if needed.