Problem/Motivation

Currently is not possible to alter translation access
There is a a GetTranslation method that determines whether you are allowed to translate entities. Currently it is not possible to alter this, the only checks that are done are based on existing permissions in core. When using the group module it may be desirable to add permissions regarding translation on group level, but there maybe many other cases where it is important to alter the permissions.

Proposed resolution

To alter the access result, it would be nice to add a hook_entity_translation_access() like hook hook_entity_access() and hook_entity_create_access().

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork drupal-2918354

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

MarcKwee created an issue. See original summary.

marckwee’s picture

StatusFileSize
new2.67 KB
seanb’s picture

Thanks Marc, this seems to make sense to me as well. It will definitely need tests. But first let's see if this is something that should be added.

+++ b/core/modules/content_translation/src/ContentTranslationHandler.php
@@ -252,7 +252,16 @@ public function getTranslationAccess(EntityInterface $entity, $op) {

@@ -252,7 +252,16 @@ public function getTranslationAccess(EntityInterface $entity, $op) {
+    $access = \Drupal::moduleHandler()->invokeAll('entity_translation_access', [$entity, $this->currentUser]);

One thing for now, it might be good to pass the operation to the hook as well.

marckwee’s picture

StatusFileSize
new1.84 KB
new2.77 KB

Thanks seanB for the feedback! I made the changes in this new patch.

marckwee’s picture

StatusFileSize
new674 bytes
new2.78 KB

Small change in the patch since the orIf method does return the access result.

idebr’s picture

Status: Active » Needs review

The last submitted patch, 2: 2918354-2.patch, failed testing. View results

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.

borisson_’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

This needs tests, probably an integration test is sufficient.

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.

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.

matthiasm11’s picture

#3018576: Content translation should allow for a language-aware access checks deprecates getTranslationAccess() which means this issue can't make it into core if so.
Please use #3056020: Content translation access control to agree on an implementation plan.

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.

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.

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.

seanb’s picture

StatusFileSize
new2.65 KB

Reroll for 9.1.x

kristiaanvandeneynde’s picture

I'd rather not see a new hook, but what I suggested in #3056020-8: Content translation access control. It would make it far easier for the Group module to support translation access and would allow us to remove most of the hard-to-alter route access check logic in favor of calling $entity->access('update translation', $account, TRUE)

Edit: But until we can actually work on such a large change, this patch would be a great band-aid.

mohit_aghera’s picture

Status: Needs work » Needs review
StatusFileSize
new5.94 KB
new3.29 KB

Added a few test cases to validate the translation create, update and delete scenarios with the overridden permissions.

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.

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.

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 tests +Needs Review Queue Initiative, +Needs change record

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

Removing the tests tag as they were added in #18

Will need a change record to announce the hook.

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

Akhil Yadav’s picture

StatusFileSize
new4.45 KB

Added patch against #18 in 10.1 version

bhanu951’s picture

Patch in #25 doesnt contain all the changes present in patch from #18

Changes to file core/modules/content_translation/content_translation.api.php is missing in #25

avpaderno’s picture

avpaderno’s picture

I have hidden the patch in comment #25.

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.

kevinvb’s picture

Maybe we should close this one in favor of Content translation access control
I've succesfully used that one to be able to provide entity access conditions on create translation, update translation or delete translation.
Without the need of an additional hook.

eduardo morales alberti made their first commit to this issue’s fork.

eduardo morales alberti’s picture

Create an MR with the patch from comment #18, on drupal 11.x the file core/modules/content_translation/tests/modules/content_translation_test/content_translation_test.module is not available.

eduardo morales alberti’s picture

Status: Needs work » Needs review
eduardo morales alberti’s picture

As comment #30 said, we should decide what is the best option to control the access.

needs-review-queue-bot’s picture

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

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

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.

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

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

samitk’s picture

I have fixed the phpcs and phpstan errors.