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:

  1. Create node/1
  2. Enable content translation
  3. Add a language
  4. Add a translation for node/1
  5. Create a "translator" role that has the permissions for Content Translation
  6. 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

Comments

dnotes created an issue. See original summary.

dnotes’s picture

Issue summary: View changes
dnotes’s picture

OK, 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.

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

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should 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.

taran2l’s picture

Status: Active » Needs review
StatusFileSize
new3.09 KB

Having this issue with patch #3018576-4: Content translation should allow for a language-aware access checks applied. Re-roll attached.

Status: Needs review » Needs work
taran2l’s picture

Updated patch puts back edit button for original language "translation"

taran2l’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
marcus_w’s picture

StatusFileSize
new3.01 KB

Rerolled patch for 8.7.1

marcus_w’s picture

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

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

Drupal 8.7.9 was released on November 6 and is the final full bugfix release for the Drupal 8.7.x series. Drupal 8.7.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.8.0 on December 4, 2019. (Drupal 8.8.0-beta1 is available for testing.)

Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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.

deepak goyal’s picture

Status: Needs work » Needs review

I have reviewed the patch #11 for the 8.8.x version.
Patch apply cleanly on version 8.8.x*

seppe beelprez’s picture

Same 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.

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

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

jefuri’s picture

bingol@ciandt.com’s picture