Skip to content

Commit

Permalink
Merge pull request KEY-TEC#4 from Metadrop/fb-permissions-any
Browse files Browse the repository at this point in the history
Permission to allow create translations in any entity
  • Loading branch information
christianwiedemann authored Jul 20, 2023
2 parents a391daf + 9492d59 commit d3a31c1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ public function ctaPermissions() {
$bundles = \Drupal::service('entity_type.bundle.info')->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)'),
]
];
}
}
}
Expand All @@ -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('bypass node access') || $account->hasPermission('cta translate any entity')) {
return TRUE;
}

if ($operation == 'update') {
$operation = 'translate';
}
Expand Down

0 comments on commit d3a31c1

Please sign in to comment.