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
- Install using standard profile in English
- Log in as a user with "translate any entity" permission - user 1 will do
- Create an English article node
- Install Content Translation module
- Add German language
- 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
- You will get a fatal error
or
- 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?
- 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
Create patch with test
Decide on where to send the user
- Review
- Commit
User interface changes
API changes
Comments
Comment #1
plachIt'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).
Comment #2
Anonymous (not verified) commentedStill 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.
Comment #3
j-leeI 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.
Comment #4
anil280988 commentedHi @J-Lee,
Did this solution worked for you? Will changing and deleting language effect/delete the current node of given language?
Comment #5
divined commentedThe same. But:
Can't resave nodes was created before adding another language.
Comment #6
divined commentedIt's upgrade problem from dev to drupal release. Old nodes can't be resaved.
Comment #7
desiboli commentedHi, 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)."
Comment #8
edutrul commentedI also got the same error, I'll troubleshoot
Comment #9
criscomSame 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.
Comment #10
criscomI 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.
Comment #11
webcultist commentedSame 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).
Comment #12
hitfactory commentedWe'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.
Comment #13
Greg Sims commentedI 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.
Comment #14
stella commentedI'm getting the same error with 8.2.x but I haven't figured what out the trigger is yet.
Comment #15
stella commentedI can reproduce this error consistently now with these steps:
Setup:
How to reproduce:
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
Comment #16
cilefen commentedComment #17
mirom commentedI reached this error during migration. After I uninstalled Content moderation module, everything is running fine. Error happened only for nodes created by uid1 user.
Comment #18
stella commentedI don't have the content moderation module enabled, never have on this site, so I don't believe that's the cause.
Comment #20
hypertext200The 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_stateentities 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.
Comment #21
stella commentedHmmm not migrating any content, so not sure where that comes into it.
Comment #22
hypertext200I'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.
Comment #23
badrange commentedWe 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.
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.
Comment #24
gnugetI 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.
Comment #25
gnugetWhile #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.
Comment #26
anacolautti commentedSo 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.
Comment #27
cilefen commentedI am updating credit for the triage work.
Comment #28
badrange commentedWe 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.
Comment #29
badrange commentedI 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
Comment #30
alexpottDiscussed 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.
Comment #31
alexpottComment #33
alexpottFixing the test and also added test improvement to \Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase
Comment #34
alexpottSo 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?
Comment #35
smashwini commentedWithout 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.
With applying the last patch #33 . Still the issue persist in Drupal 8.4.x-dev.
Comment #36
joachim commented> 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.'
Comment #37
tacituseu commentedIssue for those hitting this with content_moderation during migration #2877481: Unable to use content moderation with content migrated from Drupal 7.
Comment #40
duneblWhen applying #33 to 8.5, I got the following:
Comment #41
xanoRe-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
defaultswitch 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.Comment #43
xanoThis 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).Comment #45
kriboogh commentedThe 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...
Comment #46
brenk28 commentedThis error is also thrown under the following circumstances in a multilingual site:
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.
Comment #48
akalam commentedPatch #41 works for us. #43 don't for admin users,
Comment #49
jfhovinne commentedApplied patch #41 and unexpected error disappears. Getting a 403 instead.
Comment #51
jasa commentedI 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.
Comment #52
jasa commentedJust 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.
Comment #53
edutrul commentedI'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.
Comment #55
matsbla commentedI'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.
Comment #56
matsbla commentedComment #57
avpadernoComment #58
mr.baileysMarked #2752345: Visiting translation adding page for existing translation throws an InvalidArgumentException as a duplicate of this one.
Comment #60
matsbla commentedThis 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
Comment #63
matsbla commentedComment #64
tanubansal commentedTested 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
Comment #65
kristen polThanks 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 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.
Comment #66
kristen polUpdated
Proposed resolutionsection.Comment #67
matsbla commentedI 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:
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?
Comment #68
matsbla commentedComment #70
quietone commentedComment #73
dishabhadra commentedI 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.
Comment #74
kristen polSounds 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.
Comment #76
ikeigenwijs commentedstill an issue,
As user 1 when adding translation
´You are not authorized to access this page.´
Comment #77
ravi.shankar commentedAdded reroll of patch #60 on Drupal 9.5.x.
Comment #78
avpadernoComment #79
anybodyComment #81
smustgrave commentedDid not review but seems there are test failures from last patch.
Tagging for issue summary update for the proposed solution.
Comment #83
sokru commentedUsed the redirect approach from #2752345: Visiting translation adding page for existing translation throws an InvalidArgumentException and updated the issue summary.
Comment #85
sokru commentedRookie 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()->statusCodeEqualsso used a bit different approach.Comment #86
sokru commentedComment #87
sokru commentedFix for the typo.
Comment #89
sokru commentedAdjusting the tests to pass also on CI.
Comment #91
sokru commentedRescoped the test for content_translation where the change is.
Comment #93
sokru commentedMaybe these where left off from #3232673: \Drupal\Core\Entity\EntityInterface::label() can return a NULL.
Comment #94
sokru commented🤪
Comment #96
sokru commentedRandom test failures.
Comment #97
smustgrave commentedConfirmed 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
Comment #99
sokru commentedRandom test failure.
Comment #100
quietone commentedI'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.
This is not wrapped correctly. It should be to 80 columns.
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.".
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!
Comment #101
sokru commentedThe 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.
Comment #102
needs-review-queue-bot commentedThe 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.)
Comment #105
djsagar commentedRe-roll & Convert Patch #101 into MR. Please have a look.
Comment #106
smustgrave commented#101 applies cleanly, shows the test failures, and appears to have address.
The MR is a reroll of the test-only patch
Comment #107
larowlanHiding patches
Comment #108
larowlanThe 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
Comment #109
sokru commented@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.
Comment #110
larowlan#101 has 1800 fails
Can we move to an MR now for faster testing
Comment #111
sokru commentedTests on https://git.drupalcode.org/project/drupal/-/merge_requests/5591 now pass so setting the status back to RTBC.
Comment #112
alexpottAdded some review comments. The most important of which is:
Comment #115
smustgrave commented@hswong3i there was already an existing MR please rebase that vs opening new ones. If doing different approach please note the difference
Comment #117
robin.houtevelts commentedRebased 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
Comment #123
xjmCrediting major triage per @alexpott in #30:
Comment #125
robin.houtevelts commentedRebased 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 translationspermission.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 = trueon 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 entitypermission.translate any entitypermission, ContentTranslationManageAccessCheck::access() returnsfalsewhen a translation already exists3. 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 entitiespermission,translate any entityisn't sufficient.translate any entity+create content translationsORtranslate editable entitiestranslate any entitytranslate any entitycan access the form directly through the URL but don't see the 'Add' button on the translation overviewMy Analysis and Proposed Solution
In my opinion, the root of the problem is that ContentTranslationManageAccessCheck::access() always returns
truefor users with thetranslate any entitypermission, 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).
Comment #127
hswong3i commented