Problem/Motivation

Drupal throws a fatal error when trying to add a translation to entity which already has a translation on given language.

Original report:
This error occurred when adding an English translation of a German article (node/2/translations/add/de/en):

InvalidArgumentException: Invalid translation language (en) specified. in Drupal\Core\Entity\ContentEntityBase->addTranslation() (line 691 of core\lib\Drupal\Core\Entity\ContentEntityBase.php).

Steps to reproduce

  1. Install using standard profile in English
  2. Log in as a user with "translate any entity" permission - user 1 will do
  3. Create an English article node
  4. Install Content Translation module
  5. Add German language
  6. Enable content translation for article nodes with the default settings
  7. Go to de/node/1/translations/add/en/de and add a translation
  8. Go back to de/node/1/translations/add/en/de
  9. You will get a fatal error

or

  1. Go to content admin and use the filters to find the node I want to translate. Click its Translation operation link.
  2. Add a French translation and save it. This takes me back to the content admin page.
  3. Wait, I forgot to change something! But I can't see my node any more as it's not in the first page of results. I know, I'll just press Back and that'll get me back to the form I was just at, right?
  4. BOOM.

Note there may be other ways to reproduce this such as unchecking Create new revision in the node and translation.

Proposed resolution

Redirect to the translation overview page.

Remaining tasks

  1. Create patch with test
  2. Decide on where to send the user
  3. Review
  4. Commit

User interface changes

API changes

CommentFileSizeAuthor
#127 2137815-invalidargumentexception-invalid-translation-11.3.x-126.patch6.47 KBhswong3i
#125 2137815-225.patch1.08 KBrobin.houtevelts
#117 2137815-117.patch8.09 KBrobin.houtevelts
#101 interdiff-94-101.txt3.34 KBsokru
#101 2137815-101-failing.patch3.9 KBsokru
#101 2137815-101.patch6.69 KBsokru
#94 interdiff-93-94.txt606 bytessokru
#94 2137815-94.patch6.77 KBsokru
#93 interdiff-91-93.txt1.43 KBsokru
#93 2137815-93.patch6.77 KBsokru
#91 interdiff-89-91.txt1.95 KBsokru
#91 2137815-91.patch5.07 KBsokru
#89 interdiff-87-89.txt1.31 KBsokru
#89 2137815-89.patch4.98 KBsokru
#87 interdiff-85-87.txt859 bytessokru
#87 2137815-87.patch4.95 KBsokru
#85 interdiff-83-85.txt3.56 KBsokru
#85 2137815-85.patch4.95 KBsokru
#83 interdiff-77-83.txt2.65 KBsokru
#83 2137815-83.patch2.88 KBsokru
#77 reroll_diff_60-77.txt1.79 KBravi.shankar
#77 2137815-77.patch2.52 KBravi.shankar
#64 Screen Shot 2020-07-27 at 10.02.38 AM.png238.59 KBtanubansal
#64 Screen Shot 2020-07-27 at 9.59.48 AM.png196.62 KBtanubansal
#60 2137815-60-test-only.patch1.71 KBmatsbla
#60 2137815-60-no-tests.patch805 bytesmatsbla
#60 2137815-60.patch2.5 KBmatsbla
#55 drupal_2137815_55-combined-3014209-15.patch9.03 KBmatsbla
#55 drupal_2137815_55-no-test-fix.patch2.7 KBmatsbla
#55 drupal_2137815_55.patch3.32 KBmatsbla
#43 drupal_2137815_43.patch4.01 KBxano
#43 interdiff.txt1.45 KBxano
#41 drupal_2137815_41.patch2.95 KBxano
#33 2137815-33.patch4.44 KBalexpott
#33 31-33-interdiff.txt2.91 KBalexpott
#31 2137815-31.patch3.4 KBalexpott

Issue fork drupal-2137815

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

plach’s picture

Status: Active » Postponed (maintainer needs more info)

It's crazy but I am not able to see this: I tried both with revision enabled and disabled with no luck :(
(The testing environment is the same I used to troubleshoot #2129039: Integrity constraint violation when translating body field)

It would be great if you could post the exact steps starting from a clean installation or maybe you could post a snapshot of your test site (db + config + source files).

Anonymous’s picture

Version: 8.0.x-dev » 8.0.5
Component: entity system » language system

Still getting this:
InvalidArgumentException: Invalid translation language (en) specified. in Drupal\Core\Entity\ContentEntityBase->getTranslation() (line 748 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).
Drupal\node\Plugin\Search\NodeSearch->prepareResults(Object)
Drupal\node\Plugin\Search\NodeSearch->execute()
Drupal\search\Plugin\SearchPluginBase->buildResults()
Drupal\search\Controller\SearchController->view(Object, Object)
call_user_func_array(Array, Array)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
call_user_func_array(Object, Array)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1)
Drupal\page_cache\StackMiddleware\PageCache->fetch(Object, 1, 1)
Drupal\page_cache\StackMiddleware\PageCache->lookup(Object, 1, 1)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1)
Stack\StackedHttpKernel->handle(Object, 1, 1)
Drupal\Core\DrupalKernel->handle(Object)

Getting the errors when using the search form.
I disabled the English language and enabled Romanian.

j-lee’s picture

I got this issue too, after I playing around with the language settings.
1. Enabling German (as default language)
2. Removing EN
3. Adding EN again
4. Adding content with language UND

I truncate the "search_index" and "search_dataset" tables and re-index the site again and it works.

anil280988’s picture

Hi @J-Lee,
Did this solution worked for you? Will changing and deleting language effect/delete the current node of given language?

divined’s picture

The same. But:

Can't resave nodes was created before adding another language.

divined’s picture

It's upgrade problem from dev to drupal release. Old nodes can't be resaved.

desiboli’s picture

Hi, I get the same error when content/node is missing a translation. Shouldn't the user get a message instead like "the content has no translation" and then maby redirect the user to the frontpage or to the original language content page ? Or am I missing some configuration ?

Thank you in advance!

Error I get:
"InvalidArgumentException: Invalid translation language (en) specified. in Drupal\Core\Entity\ContentEntityBase->getTranslation() (line 745 of core/lib/Drupal/Core/Entity/ContentEntityBase.php)."

edutrul’s picture

I also got the same error, I'll troubleshoot

criscom’s picture

Same error here. Trying to manipulate the database as in #3.

What I did:

1. Installing Drupal 8.1.10 with Composer
2. Build the Drupal site with Composer
3. Install modules with Composer
4. Use a database from a clone of the site

I have a site with German as the default language and three additional languages. Only the German versions exist. Almost none of the nodes have a translation.

Problem is, I do not have the tables search_index and search_dataset. We use Search API and the tables I have are: search_api_item and search_api_task

Update: It* only occurs on nodes which were created with a specific user. In my case this was the user with ID 1.
* On nodes with the user with ID 1, I couldn't even save the original content. When I changed the author to another user, saving the node worked - but only on nodes that had no translation.

Steps to reproduce:
Edit a page where user with ID 1 is the author of the node and save => ERROR
Change author of the node from user with ID 2 to a different user and save => works

Update 2: When I try to translate a node, I get an ERROR. Changing the user doesn't help.

criscom’s picture

I have a functional version of the website on Drupal 8.1.8. So I exported the database and used it on the version of the website where translations don't work. This version of the website has Drupal 8.1.10 running.
After importing the functioning database from my Drupal 8.1.8 to my Drupal 8.1.10 version of the website the same error occurred. So I guess that error was introduced by Drupal 8.1.10.

Update: This is not true. If I downgrade to 8.1.8 the error remains. Still trying to reproduce the error and nail it down.

webcultist’s picture

Same problem for me. Only way to fix it was to delete the nodes that had been created a few drupal versions agot and recreate them (manually - I'm still in development).

hitfactory’s picture

We're seeing this on 8.2.3 when changing language from Not Specified to English or vice versa for a node that is in a menu, although the error doesn't always happen.

I suspect it is the menu bit and something to do with cache contexts which is triggering the error. Possibly it also related to a contrib module like Superfish.

Greg Sims’s picture

I am also seeing this on 8.2.3. The base language of the site is English with Spanish as the second language. I am trying to access a node in Spanish for a node that has English content but no Spanish content. This should result in displaying the English content. I receive this error instead.

My custom module implements a Block. The instruction that causes the error follows:

$node = Node::load($nid)->getTranslation($langcode);

$langcode is set to 'es'. My custom block is attempting to gain access to Spanish content when the exception fires. Should language fallback work in this case? Please note this same code works without exception when the Spanish translation exists.

stella’s picture

I'm getting the same error with 8.2.x but I haven't figured what out the trigger is yet.

stella’s picture

I can reproduce this error consistently now with these steps:

Setup:

  1. Set up multiple languages (e.g. en and fr)
  2. Translate some content
  3. Create a menu in en

How to reproduce:

  1. Translate a menu item into French by visiting a url much like /fr/admin/structure/menu/item/531/edit/translations/add/en/fr
  2. Save the translation
  3. You now have the menu item translated and available in both English and French.
  4. Revisit the page /fr/admin/structure/menu/item/531/edit/translations/add/en/fr - this might happen if you accidentally followed the wrong link or hit the back button and refreshed the page.
  5. Error appears.

It seems to happen with other types of translations too - e.g. translating a node or taxonomy term, etc and where a translation already exists in the target language for that entity.

Stella

cilefen’s picture

Version: 8.0.5 » 8.2.x-dev
Priority: Normal » Major
Status: Postponed (maintainer needs more info) » Active
mirom’s picture

Component: language system » content_moderation.module

I reached this error during migration. After I uninstalled Content moderation module, everything is running fine. Error happened only for nodes created by uid1 user.

stella’s picture

Component: content_moderation.module » language.module

I don't have the content moderation module enabled, never have on this site, so I don't believe that's the cause.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

hypertext200’s picture

The issue appeared to be when the content is from LANGCODE_NOT_SPECIFIED and trying to gain access of a referenced entity from a different language, so in my case the Content Moderation module was creating content_moderation_state entities in english which the content language is LANGCODE_NOT_SPECIFIED. So the fix for me was to re-run the migration so content will be either English or Spanish in my case but still got the error for LANGCODE_NOT_SPECIFIED content.

The content moderation appeared to use Site default language when no language specified in it's content.

So long answer short, if you run the migration for your content and your content is using LANGCODE_NOT_SPECIFIED then re-run the migration and set the LANGCODE_NOT_SPECIFIED content to LanguageInterface::LANGCODE_DEFAULT which is the site default language.

That'll fix the issue, in Drupal 8 when you have multiple languages enabled you can no longer have LANGCODE_NOT_SPECIFIED you must have LanguageInterface::LANGCODE_DEFAULT which is the site default language.

stella’s picture

Hmmm not migrating any content, so not sure where that comes into it.

hypertext200’s picture

I've see the same issue with other modules like Search API so the issue is happening when it tries to access some other language from a different context which does not have access to. I think in your post #15 it explains the similar situation.

badrange’s picture

We just saw something similar with a customer site. A node had an English and a Finnish translation, and this error popped up when trying to add a translation into Swedish.

  • None of the translations were in the menu.
  • The site doesn't have Search API added (yet).
  • We're not using the content moderation module
  • The node and it's translations were created by an editor user, and both editors and admin/uid1 had the same problem.

I edited the original version of the node, the only change was to turn off "Create new revision" and click save, and now the add translation link worked. Weird.

gnuget’s picture

I got this error today and tried what heshanlk said on #20 and it worked.

This was working few weeks ago without problem, just recently started displaying this error when I run the migration.

gnuget’s picture

While #20 fixed my article migration, I got exactly the same error when trying to migrate the node_Revision table :-/

I will continue working on this.

anacolautti’s picture

Version: 8.3.x-dev » 8.4.x-dev
Issue tags: +needs initial patch, +Needs issue summary update, +Triaged for D8 major current state

So I've reproduced the steps on comment #15 on a Drupal 8.4.x-dev site.

- installed drupal 8.4.x-dev
- installed language modules. Set up English and German
- installed content/configuration/interface translation modules

- created content, menu items and taxonomy terms
- translated them (drupal directed me to /de/node/2/translations/add/en/de )
- reloaded that url manually, got the error. The website encountered an unexpected error. Please try again later.. On the logs page I get this message: added not specified language.

When clicking on the edit button or even after submitting the translation for the first time, drupal redirects me to /de/node/2/edit. The error happens only when I enter the old URL manually.

So the site gives an error instead of just redirecting you to the already existing content, or explaining that the encountered error means that the content is already translated.

Tested this with menu items, nodes and taxonomy terms as comment #15 recommended.

Added another language to reproduce the bug explained by badrange at comment #23. Tried translating a content that already was in two languages to a third language (spanish). No issue there, not able to reproduce his issue.

Did not get to test migration and content moderation as mentioned in comment #20.

cilefen’s picture

I am updating credit for the triage work.

badrange’s picture

We saw the issue again. I was able to reproduce it on my local, and with the debugger open I see that the field triggering the error in this case was a paragraph field.

I saved the node in a different language, with no changes, and the problem went away.

badrange’s picture

I found this issue in paragraphs issue queue, the patch works for us. This may be a contrib-only issue for us, never mind my comments here :)
https://www.drupal.org/node/2857991

alexpott’s picture

Issue summary: View changes
Issue tags: +Triaged core major

Discussed with @catch, @cilefen, @effulgentsia, @lauriii and @xjm. We agreed that this is a major issue because via normal operation of your site you can generate an exception.

alexpott’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new3.4 KB

Status: Needs review » Needs work

The last submitted patch, 31: 2137815-31.patch, failed testing.

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new2.91 KB
new4.44 KB

Fixing the test and also added test improvement to \Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase

alexpott’s picture

So the only way I can get this to happen is if after adding a translation for something I return to the add URL either via the browser back button or just manually going to the url. There's nowhere in UI that the URL appears because the translation overview form knows that the translation already exists. And I wonder that since the only way to get the exception is via URL manipulation and not via clicking in the UI then is this a major bug?

Have other commenters on the issue managed to reproduce the issue in a different way?

smashwini’s picture

Without applying patch:
I am able to fix this issue for my custom content entity by checking if the entity has translation.
I created custom content entity using Drupal console.
Drupal 8 version tried with : 8.3.4 and also with 8.3.1 .

example code which I used in my CustomEntityListBuilder buildRow function.

$langCode = \Drupal::service('language_manager')->getCurrentLanguage()->getId();
    if($entity->hasTranslation($langCode)) {
    $entity = $entity->getTranslation($langCode);
   $getTitle = $entity->get('field_title')->value;
    $row['title'] = $this->l(
      $getTitle,
      new Url(
        'entity.left_floating_banner_entity.edit_form', array(
          'left_floating_banner_entity' => $entity->id(),
        )
      )
    );
    return $row + parent::buildRow($entity);
  }

With applying the last patch #33 . Still the issue persist in Drupal 8.4.x-dev.

joachim’s picture

Status: Needs review » Needs work

> And I wonder that since the only way to get the exception is via URL manipulation and not via clicking in the UI then is this a major bug?

Not just URL manipulation. Just pressing the back button will do it, and it's very easily done. Eg:

1. Go to content admin and use the filters to find the node I want to translate. Click its Translation operation link.
2. Add a French translation and save it. This takes me back to the content admin page.
3. Wait, I forgot to change something! But I can't see my node any more as it's not in the first page of results. I know, I'll just press Back and that'll get me back to the form I was just at, right?
4. BOOM.

I can confirm the patch fixes the exception, but instead I get an access denied. That's not very friendly either, and it's confusing to get that for a page that you've just been to!

Given this happens when you're trying to add a translation that already exists, I would say the best thing to do is redirect to the edit form for the translation, and show a message saying something like 'You are trying to add a translation that already exists. You may edit the existing translation instead.'

tacituseu’s picture

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dunebl’s picture

When applying #33 to 8.5, I got the following:

patching file core/modules/content_translation/src/Access/ContentTranslationManageAccessCheck.php
Hunk #1 FAILED at 86.
Hunk #2 FAILED at 105.
xano’s picture

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

Re-roll from #33.

Note that this contains significant changes that cannot be documented in an interdiff:
- Since #33, ContentTranslationManageAccessCheck::checkAccess() was introduced, which takes a lot of work out of the hands of this patch.
- This patch no longer contains the default switch case for granting access. I did not see an explicit reasoning for having it, it looked dangerous, and I reasoned I can always add it back and document it if it turns out to be necessary.
- #33 combines operation-specific access results with the entity type's translation handler's access result using OR, while other, and existing code does this using AND. The OR is now gone from this patch, because the AND in ::checkAccess() is re-used instead.

Status: Needs review » Needs work

The last submitted patch, 41: drupal_2137815_41.patch, failed testing. View results

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new1.45 KB
new4.01 KB

This makes the same ->andIf($handler->getTranslationAccess($entity, $operation)) to ->orIf($handler->getTranslationAccess($entity, $operation)) change as in #33 and the tests seem to pass. I cannot, however, comment on the validity of this change (yet).

Status: Needs review » Needs work

The last submitted patch, 43: drupal_2137815_43.patch, failed testing. View results

kriboogh’s picture

The patch above didn't resolve it for us on 8.4.7, because the user has '$op content translations' permissions, and getTranslationAccess returns true. I think access should not be granted to the add page if a translation already exists, but that's maybe an other issue.

However, I think the origin of this error is the redirect when saving the translation in the first place. What I noticed while debugging this issue, is that once the translation is saved, the form is redirected to the current url, being ../add/en/fr.
This causes the prepareTranslation to trigger again to create the translation form, causing the exception. Normally it should redirect to the translation overview page of the entity being edited. I'm still investigating this, because on an other site with exactly the same setup, we don't see this behavior...

brenk28’s picture

This error is also thrown under the following circumstances in a multilingual site:

  1. User A creates a node and sets the language to English.
  2. User A updates the node and set the language to Spanish.
  3. User B cancels user A's account and assigns the content to the anonymous user (user_cancel_reassign)

This error is thrown and the cancellation process fails. It throws the error for the revision that has the original language (English in the example). If langcode is updated to the new language (Spanish in the example) in the node_revision and node_field_revision tables then this error does not occur. Obviously, manually updating the data isn't the proper fix, but not clear on what the proper fix should be.

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

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

akalam’s picture

Patch #41 works for us. #43 don't for admin users,

jfhovinne’s picture

Applied patch #41 and unexpected error disappears. Getting a 403 instead.

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.

jasa’s picture

I am using 8.7.6 and this is happening any time I try to create a translation for a node.

"InvalidArgumentException: Invalid translation language (en) specified. en Drupal\Core\Entity\ContentEntityBase->getTranslation() (linea 873 de /var/www/web/core/lib/Drupal/Core/Entity/ContentEntityBase.php)."

Steps followed are:
- I create a node in Spanish with paragraphs.
- I try to translate the content in "English" and I got the error when I click on save.
- Then, if I visit a translation of any node, I got the error.

jasa’s picture

Just if it helps somebody, I figured out what was happening two days ago in my Drupal site:

I forgot to add "language.content_settings.x" file in sync directory, more specifically, was a "language.content_settings.taxonomy_term.vid.yml" file. The vocabulary was not translatable, but the reference field to this taxonomy in a custom content type was.

So I solved this problem by making it translatable and deleting all the existing terms.

edutrul’s picture

I've written a few test cases that are working fine:

[x] - When I create a new node in default language(English), fill in required fields, I should be able to save node successfully
[x] - When I create a new node in default language(English), fill in required fields, I should be able to save node successfully then I click on Translate tab and I should be able to see languages I wan to translate content to so I click on translate button (for a language for instance “Spanish”) the page should load fine
[x] - When I create a new node in default language(English), fill in required fields, I should be able to save node successfully then I click on Translate tab and I should be able to see languages I wan to translate content to so I click on translate button (for a language for instance “Spanish”) then I fill in the required fields and hit save button, the Spanish node should be saved successfully
[x] - When I update an existing node in the default language(English), fill in required fields, I should be able to save node successfully
[x] - When I update an existing node in default language(English), fill in required fields, I should be able to save node successfully then I click on Translate tab and I should be able to see languages I wan to translate content to so I click on translate button (for a language for instance “Spanish”) then I fill in the required fields and hit save button, the Spanish node should be saved successfully
[x] - Given a Spanish node exists I want to moderate from draft to needs review by using workbench moderation then click on save and node should be saved successfully
[x] - Given a Spanish node exists I want to moderate from needs review to published by using workbench moderation then click on save and node should be saved and published successfully
[x] - Given a Spanish published node I want to revert to draft by clicking on revisions tab, then revert the last change, then I edit the node and should be saved successfully
[x] - Given a Spanish draft node I want to click on delete translation, confirm delete translation and node shouldn’t exist anymore instead you should be redirected to translations tab (where all languages available should be displayed in order to click on translate button)

but fails when I run this scenario locally(edge case):

[ ] - When I update an existing node in default language(English), fill in required fields, I should be able to save node successfully then I click on Translate tab and I should be able to see languages I wan to translate content to so I click on translate button (for a language for instance “Spanish”) then I fill in the required fields and hit save button (then for some reason I get HEADERS ALREADY SENT) then In BROWSER I click on left arrow which is for navigating back to browser history and I get:

InvalidArgumentException: Invalid translation language (es) specified. in Drupal\Core\Entity\ContentEntityBase->addTranslation() (line 955 of /Users/edutrul/Projects/local.ibm.com/web/core/lib/Drupal/Core/Entity/ContentEntityBase.php).

So maybe node was saved with Spanish language and now we are trying to translate over again but Spanish node has been created, then why create it again? this is just edge case that has happened.

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

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

matsbla’s picture

I've tried to work a little on this, as we remove these line:
https://git.drupalcode.org/project/drupal/blob/8.9.x/core/modules/conten...
I think we need to make sure that 'translate any entity' permission is checked inside ContentTranslationHandler->getTranslationAccess()
https://git.drupalcode.org/project/drupal/blob/8.9.x/core/modules/conten...
However after fixing this I also discovered another bug because this test now fails:
https://git.drupalcode.org/project/drupal/blob/8.9.x/core/modules/node/t...
And this line at the moment pass the test:
https://git.drupalcode.org/project/drupal/blob/8.9.x/core/modules/node/t...
The test create a translation without the 'create content translations' permission...
In fact, if you have 'translate any entity' permission you can at the moment create new translations.
As far as I can see it is not visible in the UI, but you can create translations by visiting the create translation form directly, like /node/1/translations/add/en/af

The patch can be a little cluttery to test manually because another similar bug here: #3014209-15: The Translate tab is shown even though the logged-in user doesn't have the permission to translate content.
I've also uploaded a patch there, and a combined patch here.

matsbla’s picture

Status: Needs work » Needs review
avpaderno’s picture

Issue tags: -needs initial patch
mr.baileys’s picture

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

matsbla’s picture

StatusFileSize
new2.5 KB
new805 bytes
new1.71 KB

This needs re-roll as #2972308: Allow users to translate content they can edit is committed.

However, looking over my last patch again I don't think any changes are needed inside ContentTranslationHandler as it doesn in fact already check for 'translate any entity' permission.

I added the test from Xano in #41

The last submitted patch, 60: 2137815-60-no-tests.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 60: 2137815-60-test-only.patch, failed testing. View results

matsbla’s picture

Status: Needs work » Needs review
Issue tags: +Bug Smash Initiative
tanubansal’s picture

Tested via latest patch mentioned in #60. Following test steps are followed :
Install standard in English
Log in as a user with "translate any entity" permission - user 1 will do
Create an english article node
Install content translation
Add german
Enable content translation for article nodes with the default settings
Go to de/node/1/translations/add/en/de and add a translation
Go back to de/node/1/translations/add/en/de

It's working fine and can be moved to RTBC

kristen pol’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update, -Triaged for D8 major current state, -Triaged core major

Thanks for the testing.

#64 shows that the patch works for the steps to reproduce noted and shows screenshots where there is no 403 shown when going back to the translation URL. But, the test code is testing for a 403.

UPDATED: Whoops! I thought that German page was the translation. It is the access denied text. Ignore the above.

In #36, for an old patch:

I can confirm the patch fixes the exception, but instead I get an access denied. That's not very friendly either, and it's confusing to get that for a page that you've just been to!

I would agree that giving a 403 for going to the page is not good UX. IMO, it would be good to redirect to the existing translation.

Side note: Since Drupal 9 is out, I removed the Drupal 8 triage tags.

kristen pol’s picture

Issue summary: View changes

Updated Proposed resolution section.

matsbla’s picture

it would be good to redirect to the existing translation.

I think that if the user have edit permissions, maybe we should redirect them back to the edit form? If not you would be redirected to the exact same page as you were just viewing (the newly created translation), not sure if that is good UX? I also wonder how we should handle cases where the user is not allowed to view the translation, e.g. because of it's moderation state.

I think the patch solve the bug, which at the moment give access for users with "translate any entity" permission to:

  • add translations, even if they don't have any add translation permission.
  • edit translations even if they don't have edit translation permission.
  • delete translations, even when they don't have any delete translation permission.

Maybe this should be solved first and then we could create a follow-up issue that where we solve the UX issue with redirects of already existing translations with a more throughout though on different scenarios?

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

quietone’s picture

Issue summary: View changes

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

dishabhadra’s picture

I was able to reproduce this issue with the steps mentioned here #15
Instead of showing 403, it would be good to redirect to the existing translation.

For redirect, I applied this patch https://www.drupal.org/project/drupal/issues/2752345#comment-12800665 it is working fine for Drupal 9.2.7.

kristen pol’s picture

Sounds like we need to decide if we continue with the patch here or consider using the patch from #2752345: Visiting translation adding page for existing translation throws an InvalidArgumentException.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

ikeigenwijs’s picture

Status: Needs review » Needs work

still an issue,
As user 1 when adding translation
´You are not authorized to access this page.´

ravi.shankar’s picture

StatusFileSize
new2.52 KB
new1.79 KB

Added reroll of patch #60 on Drupal 9.5.x.

avpaderno’s picture

Status: Needs work » Needs review

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs issue summary update

Did not review but seems there are test failures from last patch.

Tagging for issue summary update for the proposed solution.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

sokru’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs issue summary update
StatusFileSize
new2.88 KB
new2.65 KB

Status: Needs review » Needs work

The last submitted patch, 83: 2137815-83.patch, failed testing. View results

sokru’s picture

StatusFileSize
new4.95 KB
new3.56 KB

Rookie mistake on previous patch. Also the permissions needed a bit of tweaking. For some reason the redirect (302) statuscode was not possible to catch with $this->assertSession()->statusCodeEquals so used a bit different approach.

sokru’s picture

Status: Needs work » Needs review
sokru’s picture

StatusFileSize
new4.95 KB
new859 bytes

Fix for the typo.

Status: Needs review » Needs work

The last submitted patch, 87: 2137815-87.patch, failed testing. View results

sokru’s picture

Status: Needs work » Needs review
StatusFileSize
new4.98 KB
new1.31 KB

Adjusting the tests to pass also on CI.

Status: Needs review » Needs work

The last submitted patch, 89: 2137815-89.patch, failed testing. View results

sokru’s picture

Status: Needs work » Needs review
StatusFileSize
new5.07 KB
new1.95 KB

Rescoped the test for content_translation where the change is.

Status: Needs review » Needs work

The last submitted patch, 91: 2137815-91.patch, failed testing. View results

sokru’s picture

Status: Needs work » Needs review
StatusFileSize
new6.77 KB
new1.43 KB
sokru’s picture

StatusFileSize
new6.77 KB
new606 bytes

🤪

Status: Needs review » Needs work

The last submitted patch, 94: 2137815-94.patch, failed testing. View results

sokru’s picture

Status: Needs work » Needs review

Random test failures.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Go to content admin and use the filters to find the node I want to translate. Click its Translation operation link.
Add a French translation and save it. This takes me back to the content admin page.
Wait, I forgot to change something! But I can't see my node any more as it's not in the first page of results. I know, I'll just press Back and that'll get me back to the form I was just at, right?

Confirmed the issue following these steps.
Applying patch #94 resolved the issue for me.

Issue summary matches the solution where I'm redirected to translation overview
Patch also appears to have test coverage.

RTBC+1

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 94: 2137815-94.patch, failed testing. View results

sokru’s picture

Status: Needs work » Reviewed & tested by the community

Random test failure.

quietone’s picture

Status: Reviewed & tested by the community » Needs work

I'm triaging RTBC issues. I read the IS and then read the patch. I did not read all the comments or review or test the patch.

Thanks everyone for working on this old bug!

I found some things that should be fixed before this is ready for commit.

  1. +++ b/core/modules/content_translation/src/Controller/ContentTranslationController.php
    @@ -362,6 +362,12 @@ public function add(LanguageInterface $source, LanguageInterface $target, RouteM
    +    // If the entity already has the target translation,
    +    // redirect to the translation overview page.
    

    This is not wrapped correctly. It should be to 80 columns.

  2. +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php
    @@ -120,6 +120,23 @@ protected function doTestBasicTranslation() {
    +    // Assert that once a translation exists, the recurring calls to route is
    +    // redirected to the translations overview page.
    

    I think we can remove the part about 'calls to route'. How about, "Asserts that once a translation exists the user is redirected to the translations overview page.".

  3. +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php
    @@ -120,6 +120,23 @@ protected function doTestBasicTranslation() {
    +      $this->assertStringContainsString('/entity_test_mul_changed/manage/1/translations', $this->getUrl(), 'Correct path after redirect');
    ...
    +      $this->assertStringContainsString('/entity_test_mul_changed/manage/1/translations', $this->getUrl(), 'Correct path after redirect');
    

    Messages are no longer used in assertion, unless needed for clarification as in a for loop.

Also, this should also have a fail test. Therefore setting to NW. This is close!

sokru’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new6.69 KB
new3.9 KB
new3.34 KB

The attached patch should handle the issues found on #100. Also included a patch that shows the failing.
Also tried to trim the summary of the issue to first phrase on the issue summary.

needs-review-queue-bot’s picture

Status: Needs review » Needs work

The Needs Review Queue Bot tested this issue.

While you are making the above changes, we recommend that you convert this patch to a merge request. Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)

djsagar made their first commit to this issue’s fork.

djsagar’s picture

Status: Needs work » Needs review

Re-roll & Convert Patch #101 into MR. Please have a look.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

#101 applies cleanly, shows the test failures, and appears to have address.

The MR is a reroll of the test-only patch

larowlan’s picture

Status: Reviewed & tested by the community » Needs work

Hiding patches

larowlan’s picture

The MR shows fails https://git.drupalcode.org/issue/drupal-2137815/-/pipelines/56688/test_r... for content translation tests, so that feels like it might be a genuine issue

sokru’s picture

Status: Needs work » Reviewed & tested by the community

@larowlan as mentioned on #106, "The MR is a reroll of the test-only patch". The actual patch on #101 still applies and passes the tests.

larowlan’s picture

Status: Reviewed & tested by the community » Needs work

#101 has 1800 fails

Can we move to an MR now for faster testing

sokru’s picture

Status: Needs work » Reviewed & tested by the community

Tests on https://git.drupalcode.org/project/drupal/-/merge_requests/5591 now pass so setting the status back to RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Added some review comments. The most important of which is:

Is this the correct behaviour? The original request for this behaviour mentioned at least adding a message telling the user what had happened. But I don't understand the rationale for going to the translation overview page instead of the edit page for the translation which is surely closer to the user intended.

hswong3i made their first commit to this issue’s fork.

smustgrave’s picture

@hswong3i there was already an existing MR please rebase that vs opening new ones. If doing different approach please note the difference

robin.houtevelts made their first commit to this issue’s fork.

robin.houtevelts’s picture

StatusFileSize
new8.09 KB

Rebased the MR that got previously reviewed in #111, #112
Also adding a patch file for cweagans/composer-patches usage

As #112 mentioned, there are a few outstanding questions left

xjm credited catch.

xjm credited effulgentsia.

xjm credited lauriii.

xjm’s picture

Crediting major triage per @alexpott in #30:

catch, cilefen, effulgentsia, lauriii, xjm

robin.houtevelts’s picture

StatusFileSize
new1.08 KB

Rebased the MR that got previously reviewed in #111, #112
Also adding a patch file for cweagans/composer-patches usage for those that are okay with the current redirect solution and need to move on with their lives.

As #112 mentioned, there are a few outstanding questions left.

Seeing how this hasn't been picked up by anyone else in the last 6 months I took a look as well:

Weird Things I encountered

1. Redirect to potentially Forbidden Overview Page

We've decided (did we?) to redirect to the translation overview page when visiting the "add translation" URL if a translation already exists. However, this overview page requires the view test entity translations permission.

What should we do if the user lacks the permission to see the translation overview?

This is the reported "user 1" issue in comment #76. Since https://www.drupal.org/node/2910500 "user 1" isn't guaranteed to have all permissions. There was a failing test case for it which resolved itself after I enabled $usesSuperUserAccessPolicy = true on the test (which isn't a solution but confirmed my suspicion).

2. Conditional Redirect Based on Permission

The redirect to translation overview only happens if you have the translate any entity permission.

  • Without translate any entity permission, ContentTranslationManageAccessCheck::access() returns false when a translation already exists
  • This means users with limited translation permissions get access denied instead of being redirected to the overview
  • The behavior is inconsistent - some users get redirected, others get blocked

3. Add Button Permission Inconsistency (unrelated to this issue but worth writing down)

The 'Add' button on translation overview only displays when you have translate editable entities permission, translate any entity isn't sufficient.

  • Add button uses ContentTranslationHandler::getTranslationAccess() which requires translate any entity + create content translations OR translate editable entities
  • Add translation form route uses ContentTranslationManageAccessCheck which allows access with just translate any entity
  • Users with translate any entity can access the form directly through the URL but don't see the 'Add' button on the translation overview

My Analysis and Proposed Solution

In my opinion, the root of the problem is that ContentTranslationManageAccessCheck::access() always returns true for users with the translate any entity permission, even if the translation already exists.

When I look at that method, I don't see why that "early return" is in there. It was added in https://www.drupal.org/project/drupal/issues/2431281 and seems out of place.

If we simply remove that "early return", the route will correctly show a 403 Forbidden error if the translation already exists.

For me, this is a better solution. A 403 error is less confusing than a redirect, especially since this problem happens when using the browser's "Back" button. When I go "Back," I expect to see the previous url, not get redirected to a new one (which also messes up my browser history).

hswong3i’s picture

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.