You are here

public function AccessUnpublishedPermissions::permissions in Access unpublished 8

Permissions callback.

Return value

array Returns permissions for all nodes.

1 string reference to 'AccessUnpublishedPermissions::permissions'
access_unpublished.permissions.yml in ./access_unpublished.permissions.yml
access_unpublished.permissions.yml

File

src/AccessUnpublishedPermissions.php, line 56

Class

AccessUnpublishedPermissions
Calculates the permissions for access_unpublished.

Namespace

Drupal\access_unpublished

Code

public function permissions() {
  $permissions = [];
  $definitions = $this->entityTypeManager
    ->getDefinitions();
  foreach ($definitions as $definition) {
    if (AccessUnpublished::applicableEntityType($definition)) {
      $permission = 'access_unpublished ' . $definition
        ->id();
      if ($definition
        ->get('bundle_entity_type')) {
        $bundles = $this->entityTypeManager
          ->getStorage($definition
          ->getBundleEntityType())
          ->loadMultiple();
        foreach ($bundles as $bundle) {
          $permissions[$permission . ' ' . $bundle
            ->id()] = [
            'title' => $this
              ->t('Access unpublished %bundle @type', [
              '%bundle' => strtolower($bundle
                ->label()),
              '@type' => $definition
                ->getPluralLabel(),
            ]),
          ];
        }
      }
      else {
        $permissions[$permission] = [
          'title' => $this
            ->t('Access unpublished @type', [
            '@type' => $definition
              ->getPluralLabel(),
          ]),
        ];
      }
    }
  }
  return $permissions;
}