From d49f2f9cb4d64b1e1a12de00f071cdeb048bb725 Mon Sep 17 00:00:00 2001 From: Omar Date: Thu, 16 Dec 2021 16:56:40 +0100 Subject: [PATCH 1/2] Permission to allow create translations in any entity --- src/Permissions.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Permissions.php b/src/Permissions.php index 429bbae..1154995 100644 --- a/src/Permissions.php +++ b/src/Permissions.php @@ -69,7 +69,11 @@ public function ctaPermissions() { $bundles = \Drupal::entityManager()->getBundleInfo($entity_type->id()); foreach ($bundles as $bundle_id => $bundle_lable) { if ($this->contentTranslationManager->isEnabled($entity_type->id(), $bundle_id)) { - $perms += $this->buildPermissions($entity_type, $bundle_id, $bundle_lable['label']); + $perms += $this->buildPermissions($entity_type, $bundle_id, $bundle_lable['label']) + [ + "cta translate any entity" => [ + 'title' => $this->t('Translate any entity (with assigned language)'), + ] + ]; } } } @@ -93,6 +97,10 @@ public function ctaPermissions() { * Return true if user has permission. */ public static function hasPermission($operation, $entity_type_id, $bundle_id, AccountInterface $account) { + if ($account->hasPermission('cta translate any entity')) { + return TRUE; + } + if ($operation == 'update') { $operation = 'translate'; } From 9492d590369b54ae9806bc2a22e95c97e84fb553 Mon Sep 17 00:00:00 2001 From: Omar Date: Tue, 4 Jan 2022 14:52:21 +0100 Subject: [PATCH 2/2] Allow user access to translations when they bypass the node access --- src/Permissions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Permissions.php b/src/Permissions.php index 1154995..92f54b4 100644 --- a/src/Permissions.php +++ b/src/Permissions.php @@ -97,7 +97,7 @@ public function ctaPermissions() { * Return true if user has permission. */ public static function hasPermission($operation, $entity_type_id, $bundle_id, AccountInterface $account) { - if ($account->hasPermission('cta translate any entity')) { + if ($account->hasPermission('bypass node access') || $account->hasPermission('cta translate any entity')) { return TRUE; }