function ContentTranslationPermissions::contentPermissions

Same name in other branches
  1. 9 core/modules/content_translation/src/ContentTranslationPermissions.php \Drupal\content_translation\ContentTranslationPermissions::contentPermissions()
  2. 8.9.x core/modules/content_translation/src/ContentTranslationPermissions.php \Drupal\content_translation\ContentTranslationPermissions::contentPermissions()
  3. 10 core/modules/content_translation/src/ContentTranslationPermissions.php \Drupal\content_translation\ContentTranslationPermissions::contentPermissions()

Returns an array of content translation permissions.

Return value

array

1 string reference to 'ContentTranslationPermissions::contentPermissions'
content_translation.permissions.yml in core/modules/content_translation/content_translation.permissions.yml
core/modules/content_translation/content_translation.permissions.yml

File

core/modules/content_translation/src/ContentTranslationPermissions.php, line 72

Class

ContentTranslationPermissions
Provides dynamic permissions for the content_translation module.

Namespace

Drupal\content_translation

Code

public function contentPermissions() {
    $permissions = [];
    // Create a translate permission for each enabled entity type and (optionally)
    // bundle.
    foreach ($this->entityTypeManager
        ->getDefinitions() as $entity_type_id => $entity_type) {
        if ($permission_granularity = $entity_type->getPermissionGranularity()) {
            switch ($permission_granularity) {
                case 'bundle':
                    foreach ($this->entityTypeBundleInfo
                        ->getBundleInfo($entity_type_id) as $bundle => $bundle_info) {
                        if ($this->contentTranslationManager
                            ->isEnabled($entity_type_id, $bundle)) {
                            $permissions["translate {$bundle} {$entity_type_id}"] = $this->buildBundlePermission($entity_type, $bundle, $bundle_info);
                        }
                    }
                    break;
                case 'entity_type':
                    if ($this->contentTranslationManager
                        ->isEnabled($entity_type_id)) {
                        $permissions["translate {$entity_type_id}"] = [
                            'title' => $this->t('Translate @entity_label', [
                                '@entity_label' => $entity_type->getSingularLabel(),
                            ]),
                            'dependencies' => [
                                'module' => [
                                    $entity_type->getProvider(),
                                ],
                            ],
                        ];
                    }
                    break;
            }
        }
    }
    return $permissions;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.