function BundlePermissionHandlerTrait::generatePermissions

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/BundlePermissionHandlerTrait.php \Drupal\Core\Entity\BundlePermissionHandlerTrait::generatePermissions()
  2. 10 core/lib/Drupal/Core/Entity/BundlePermissionHandlerTrait.php \Drupal\Core\Entity\BundlePermissionHandlerTrait::generatePermissions()

Builds a permissions array for the supplied bundles.

Parameters

\Drupal\Core\Entity\EntityInterface[] $bundles: An array of bundles to generate permissions for.

callable $permission_builder: A callable to generate the permissions for a particular bundle. Returns an array of permissions. See PermissionHandlerInterface::getPermissions() for the array structure.

Return value

array Permissions array. See PermissionHandlerInterface::getPermissions() for the array structure.

See also

\Drupal\user\PermissionHandlerInterface::getPermissions()

5 calls to BundlePermissionHandlerTrait::generatePermissions()
BlockContentPermissions::blockTypePermissions in core/modules/block_content/src/BlockContentPermissions.php
Build permissions for each block type.
BundlePermissionHandlerTraitTest::testGeneratePermissions in core/tests/Drupal/KernelTests/Core/Entity/BundlePermissionHandlerTraitTest.php
@covers ::generatePermissions
MediaPermissions::mediaTypePermissions in core/modules/media/src/MediaPermissions.php
Returns an array of media type permissions.
NodePermissions::nodeTypePermissions in core/modules/node/src/NodePermissions.php
Returns an array of node type permissions.
TaxonomyPermissions::permissions in core/modules/taxonomy/src/TaxonomyPermissions.php
Get taxonomy permissions.

File

core/lib/Drupal/Core/Entity/BundlePermissionHandlerTrait.php, line 26

Class

BundlePermissionHandlerTrait
Provides a method to simplify generating bundle level permissions.

Namespace

Drupal\Core\Entity

Code

protected function generatePermissions(array $bundles, callable $permission_builder) {
    $permissions = [];
    foreach ($bundles as $bundle) {
        $permissions += array_map(function (array $perm) use ($bundle) {
            // This permission is generated on behalf of a bundle, therefore
            // add the bundle as a config dependency.
            $perm['dependencies'][$bundle->getConfigDependencyKey()][] = $bundle->getConfigDependencyName();
            return $perm;
        }, $permission_builder($bundle));
    }
    return $permissions;
}

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