public function EntityPrintPermissions::getPermissions in Entity Print 8.2
Same name and namespace in other branches
- 8 src/EntityPrintPermissions.php \Drupal\entity_print\EntityPrintPermissions::getPermissions()
Returns an array of entity_print permissions.
1 string reference to 'EntityPrintPermissions::getPermissions'
File
- src/
EntityPrintPermissions.php, line 63
Class
- EntityPrintPermissions
- Provides dynamic permissions for entity_print.
Namespace
Drupal\entity_printCode
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('%entity_label: Use all print engines', [
'%entity_label' => $content_entity_type
->getLabel(),
]),
];
// Add 1 permission for each bundle.
$entity_type_bundles = $this->entityTypeBundleInfo
->getBundleInfo($content_entity_type
->id());
// Don't bother creating a new permission if there is only 1 bundle.
if (count($entity_type_bundles) === 1) {
continue;
}
foreach ($entity_type_bundles as $bundle_key => $entity_type_bundle) {
$permissions['entity print access bundle ' . $bundle_key] = [
'title' => $this
->t('%entity_bundle_label: Use all print engines', [
'%entity_bundle_label' => $entity_type_bundle['label'],
]),
];
}
}
return $permissions;
}