Problem/Motivation
Our QA team just found this one. It's possible for a default D8/9 site to throw an error 500 for content editors with very few steps: Attempt to add a translation that already exists.
Steps to reproduce
Deploy a standard D9.2.x-dev site using git clone https://github.com/drupal-composer/drupal-project.git
Enable Language and Content Translation modules.
Enable French as a second langauge
Modify Basic Page so that it can be translated.
Create a Basic Page in English.
Open Translation page and verify a translation exists in English, but not French.
Middle Click on the Add button for French.
In this new tab, create a French translation of the original content and save.
Close the new tab, and return to the already translation page.
Click "Add" on the French content again (e.g "http://drupal-project.lndo.site/fr/node/1/translations/add/en/fr")
The following error is thrown:
Uncaught PHP Exception InvalidArgumentException: "Invalid translation language (fr) specified." at /app/web/core/lib/Drupal/Core/Entity/ContentEntityBase.php line 955, referer: http://drupal-project.lndo.site/node/1/translations
This can be replicated with any translatable content. Just Add a translation, save it, then go back to the same Add URL.
Proposed resolution
While this is an edge case, it shouldn't be so easy for content editors to produce a PHP error. This should instead be caught and throw and error "This content has already been translated" - or perhaps redirect the user to the existing translated edit page.
Remaining tasks
Update target branch
Add tests
Review
Commit
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|
Issue fork drupal-3209204
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
Comment #2
trevorbradley commentedComment #4
randalv commentedI would like to second this, this is not okay behaviour.
At the very least, we shouldn't throw an exception but show a regular admin page saying the translation already exists, with perhaps a link to the edit page.
Comment #5
randalv commentedComment #6
randalv commentedTypo in last patch file rendered it unable to apply.
Comment #8
johnwebdev commentedI run into this problem as well, but for menus. I also noticed the behavior depends on which Browser you use.
Preparation:
1. Add a menu
With Chrome browser
2. Add a menu link
3. Translate that menu link
4. Press Back button
5. You end up on the Add translation page
6. Try Save, you will get the error "Invalid translation language specified"
In Edge
2. Add a menu link
3. Translate that menu link
4. Press Back button
5. You will get the Invalid translation language specified
Comment #11
mpp commentedThe same error happens when trying to add a translation for menu links e.g. /fr/admin/structure/menu/item/14/edit/translations/add/nl/fr
Comment #12
ikeigenwijs commentedwe have the same error for
untranslated contentthe node is translated, I saw it in the url,but is listed as untranslated
just using the add button to add translation
InvalidArgumentException: Invalid translation language (en) specified. in Drupal\Core\Entity\ContentEntityBase->addTranslation() (line 956 of /core/lib/Drupal/Core/Entity/ContentEntityBase.php).
Comment #15
dieterholvoet commentedI changed the MR to redirect to the target translation edit form instead of the translation overview, this seems more user friendly.
The MR also fixes the issue for menu links.
Comment #16
smustgrave commentedUpdated remaining tasks section.
Comment #18
uridrupal commentedI have tested and it works. I am not having issues translating block content anymore.
Comment #19
weseze commentedCan confirm this error.
Some of our content editors are getting stuck in this flow by mass translating in dozens of browser tabs and having some duplicates (already translated nodes) open.
Very easy to get in to this problem, very hard te understand without technical knowledge why this is a problem...
MR from DieterHolvoet fixes the issue nicely. Thanks!
Comment #21
dieterholvoet commented@johnwebdev could you change the MR to target the main branch?
Comment #24
dieterholvoet commentedI started a new MR instead.
Comment #25
michaelsoetaertCreated patch based on current MR for usage with composer.
Comment #27
andras_szilagyi commentedI've added a test and fixed my concerns, in addition the pipeline was failing for unrelated, so I rebased the fork branch now its better but there is still an issue in the main branch, anyway, ready for review.
Comment #28
claudiu.cristeaI came here after experiencing the same issue, randomly on macOS & Safari. It seems that, in some circumstances, the Mac touchpad is triggering a browser Back. But I've learned that the same error is triggered if, while adding a translation, other user adds the same translation and saves. Then, when you save, will get the same error. This is weird because in such scenario Drupal expected behavior is to invalidate your submission with the "The form has become outdated..."
The fix is simple and is just a defensive check. By patching my codebase I cannot reproduce anymore the bug. It has also tests, so from my POV is RTBC.
Comment #29
claudiu.cristeaComment #33
catchCommitted/pushed to main, 11.x and 11.4.x, thanks!