You are here

public function EntityPrintPermissions::getPermissions in Entity Print 8

Same name and namespace in other branches
  1. 8.2 src/EntityPrintPermissions.php \Drupal\entity_print\EntityPrintPermissions::getPermissions()

Returns an array of entity_print permissions.

1 string reference to 'EntityPrintPermissions::getPermissions'
entity_print.permissions.yml in ./entity_print.permissions.yml
entity_print.permissions.yml

File

src/EntityPrintPermissions.php, line 64

Class

EntityPrintPermissions
Provides dynamic permissions for entity_print.

Namespace

Drupal\entity_print

Code

public function getPermissions() {

  /** @var \Drupal\Core\Entity\EntityTypeInterface[] $content_entity_types */

  // Get all EntityTypes for the group "content".
  $content_entity_types = array_filter($this->entityTypeManager
    ->getDefinitions(), function ($entity_type) {
    return $entity_type
      ->getGroup() === 'content';
  });
  $permissions = [];
  foreach ($content_entity_types as $key => $content_entity_type) {
    $permissions['entity print access type ' . $content_entity_type
      ->id()] = [
      'title' => $this
        ->t('Use Entity Print for all bundles of type %entity_label', [
        '%entity_label' => $content_entity_type
          ->getLabel(),
      ]),
    ];

    // Add 1 permission for each bundle.
    $entity_type_bundles = $this->entityTypeBundleInfo
      ->getBundleInfo($content_entity_type
      ->id());
    foreach ($entity_type_bundles as $bundle_key => $entity_type_bundle) {
      $permissions['entity print access bundle ' . $bundle_key] = [
        'title' => $this
          ->t('Use entity print for bundle %entity_label - %entity_bundle_label', [
          '%entity_label' => $content_entity_type
            ->getLabel(),
          '%entity_bundle_label' => $entity_type_bundle['label'],
        ]),
      ];
    }
  }
  return $permissions;
}