EntityPrintPermissions.php in Entity Print 8.2
File
src/EntityPrintPermissions.php
View source
<?php
namespace Drupal\entity_print;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\StringTranslation\TranslationManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
class EntityPrintPermissions implements ContainerInjectionInterface {
use StringTranslationTrait;
protected $entityTypeManager;
protected $entityTypeBundleInfo;
public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, TranslationManager $translation_manager) {
$this->entityTypeManager = $entity_type_manager;
$this->entityTypeBundleInfo = $entity_type_bundle_info;
$this->stringTranslation = $translation_manager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager'), $container
->get('entity_type.bundle.info'), $container
->get('string_translation'));
}
public function getPermissions() {
$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(),
]),
];
$entity_type_bundles = $this->entityTypeBundleInfo
->getBundleInfo($content_entity_type
->id());
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;
}
}