function ContentTranslationPermissions::buildBundlePermission

Same name in other branches
  1. 10 core/modules/content_translation/src/ContentTranslationPermissions.php \Drupal\content_translation\ContentTranslationPermissions::buildBundlePermission()
  2. 11.x core/modules/content_translation/src/ContentTranslationPermissions.php \Drupal\content_translation\ContentTranslationPermissions::buildBundlePermission()

Builds a content translation permission array for a bundle.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type.

string $bundle: The bundle to build the translation permission for.

array $bundle_info: The bundle info.

Return value

array The permission details, keyed by 'title' and 'dependencies'.

1 call to ContentTranslationPermissions::buildBundlePermission()
ContentTranslationPermissions::contentPermissions in core/modules/content_translation/src/ContentTranslationPermissions.php
Returns an array of content translation permissions.

File

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

Class

ContentTranslationPermissions
Provides dynamic permissions for the content_translation module.

Namespace

Drupal\content_translation

Code

private function buildBundlePermission(EntityTypeInterface $entity_type, string $bundle, array $bundle_info) {
    $permission = [
        'title' => $this->t('Translate %bundle_label @entity_label', [
            '@entity_label' => $entity_type->getSingularLabel(),
            '%bundle_label' => $bundle_info['label'] ?? $bundle,
        ]),
    ];
    // If the entity type uses bundle entities, add a dependency on the bundle.
    $bundle_entity_type = $entity_type->getBundleEntityType();
    if ($bundle_entity_type && ($bundle_entity = $this->entityTypeManager
        ->getStorage($bundle_entity_type)
        ->load($bundle))) {
        $permission['dependencies'][$bundle_entity->getConfigDependencyKey()][] = $bundle_entity->getConfigDependencyName();
    }
    else {
        $permission['dependencies']['module'][] = $entity_type->getProvider();
    }
    return $permission;
}

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