Content Translation module provides routes to translate any entity through a route subscriber and the following link templates as defined in a hook_entity_alter implementation:
$translations_path = $entity_type->getLinkTemplate('canonical') . '/translations';
$entity_type->setLinkTemplate('drupal:content-translation-overview', $translations_path);
$entity_type->setLinkTemplate('drupal:content-translation-add', $translations_path . '/add/{source}/{target}');
$entity_type->setLinkTemplate('drupal:content-translation-edit', $translations_path . '/edit/{language}');
$entity_type->setLinkTemplate('drupal:content-translation-delete', $translations_path . '/delete/{language}');
However, those routes may not accessible to any user with permission to edit the entity itself, even if that user is user 1. From https://www.drupal.org/node/2677778#comment-11022487:
By design, it appears, ContentTranslationManageAccessCheck blocks editors access to the entity.$entity_type_id.content_translation_edit route:
// Editors have no access to the translation operations, as entity // access already grants them an equal or greater access level. $templates = ['update' => 'edit-form', 'delete' => 'delete-form']; if ($entity->access($operation) && $entity_type->hasLinkTemplate($templates[$operation])) { return AccessResult::forbidden()->cachePerPermissions(); }
It seems wrong to me that user 1, or any user with the admin role, should get a 403 access denied for an operation that a translator can accomplish. This seems to be true even if user 1 also has the translator role.
Because of this decision, one cannot count on the translation link templates to be a reliable path for anyone who should be able to translate content. It is impossible, for example, to create a view that will allow administrators to edit content translations in any language with a single click; the edit-form link template points to whatever language in which the current page is being viewed, and the drupal:content-translation-edit link template is 403. Even on the translations overview page, this situation leads to many workarounds that seem inherently buggy, e.g. (from the same comment referenced above):
And the overview controller always provides editors with links to the entity edit page:
if ($update_access->isAllowed() && $entity_type->hasLinkTemplate('edit-form')) { $links['edit']['url'] = $entity->urlInfo('edit-form'); $links['edit']['language'] = $language; } elseif (!$is_original && $translation_access->isAllowed()) { $links['edit']['url'] = $edit_url; }But the entity.$entity_type_id.edit_form route always loads the translation of the currently negotiated language.
Steps to reproduce:
- Create node/1
- Enable content translation
- Add a language
- Add a translation for node/1
- Create a "translator" role that has the permissions for Content Translation
- Create a user with the "translator" role
Expected behavior:
- As the translator user, node/1/translations/edit/{langcode} helps me translate the content
- As the translator user, node/1/translations/delete/{langcode} helps me translate the content
- As the admin user or user 1, node/1/translations/edit/{langcode} helps me translate the content
- As the admin user or user 1, node/1/translations/delete/{langcode} helps me translate the content
What happens instead:
- As the translator user, node/1/translations/edit/{langcode} is available
- As the translator user, node/1/translations/delete/{langcode} is available
- As the admin user or user 1, node/1/translations/edit/{langcode} is 403 Access Denied
- As the admin user or user 1, node/1/translations/delete/{langcode} is 403 Access Denied
Proposed resolution:
- Remove the access checks that deny access to admin users
- Optionally remove workarounds to send admin users to edit-form link template
- Optionally redirect admin users to the proper edit form instead of 403
| Comment | File | Size | Author |
|---|---|---|---|
| #19 | drupal-admin_content_translation_403-2901898-12.patch | 1.13 KB | bingol@ciandt.com |
| #11 | drupal-admin_content_translation_403-2901898-11.patch | 3.01 KB | marcus_w |
Comments
Comment #2
dnotes commentedComment #3
dnotes commentedOK, well I'm just going to put something out there for discussion. Here's a patch that achieves the functionality I feel like I'm expecting: The translate urls all work, and the interface language does not change unexpectedly when performing translation operations.
Comment #6
taran2lHaving this issue with patch #3018576-4: Content translation should allow for a language-aware access checks applied. Re-roll attached.
Comment #8
taran2lUpdated patch puts back edit button for original language "translation"
Comment #9
taran2lComment #11
marcus_w commentedRerolled patch for 8.7.1
Comment #12
marcus_w commentedComment #14
deepak goyal commentedI have reviewed the patch #11 for the 8.8.x version.
Patch apply cleanly on version 8.8.x*
Comment #15
seppe beelprez commentedSame as #14, patch #11 works for the 8.9.x version.
Patch apply cleanly on version 8.9.x*
Searched for hours on this weird issue. I could translate everything when I was logged in as admin. But when I logged in with a editor role. If I wanted to add a English translation on a already existing Dutch translation, I got a Access denied.
Still one weird thing is if I added the English translation and save the node, instead of redirecting me to the English version, it redirects me to the original Dutch version.
Comment #18
jefuri commentedThis is a duplicate issue of https://www.drupal.org/project/drupal/issues/2451693
Comment #19
bingol@ciandt.com commented