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
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | interdiff-2918354-16-18.txt | 3.29 KB | mohit_aghera |
| #18 | 2918354-18.patch | 5.94 KB | mohit_aghera |
| #16 | 2918354-16.patch | 2.65 KB | seanb |
| #5 | 2918354-5.patch | 2.78 KB | marckwee |
| #5 | interdiff-4-5.txt | 674 bytes | marckwee |
Issue fork drupal-2918354
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
marckwee commentedComment #3
seanbThanks 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.
One thing for now, it might be good to pass the operation to the hook as well.
Comment #4
marckwee commentedThanks seanB for the feedback! I made the changes in this new patch.
Comment #5
marckwee commentedSmall change in the patch since the orIf method does return the access result.
Comment #6
idebr commentedComment #9
borisson_This needs tests, probably an integration test is sufficient.
Comment #12
matthiasm11 commented#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.
Comment #16
seanbReroll for 9.1.x
Comment #17
kristiaanvandeneyndeI'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.
Comment #18
mohit_aghera commentedAdded a few test cases to validate the translation create, update and delete scenarios with the overridden permissions.
Comment #23
smustgrave commentedThis 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.
Comment #25
Akhil Yadav commentedAdded patch against #18 in 10.1 version
Comment #26
bhanu951 commentedPatch 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
Comment #27
avpadernoComment #28
avpadernoI have hidden the patch in comment #25.
Comment #30
kevinvb commentedMaybe 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.
Comment #33
eduardo morales albertiCreate 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.
Comment #34
eduardo morales albertiComment #35
eduardo morales albertiAs comment #30 said, we should decide what is the best option to control the access.
Comment #36
needs-review-queue-bot commentedThe 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.
Comment #40
samitk commentedI have fixed the phpcs and phpstan errors.