TcaPermissionGenerator.php in Token Content Access 8
File
src/TcaPermissionGenerator.php
View source
<?php
namespace Drupal\tca;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\tca\Plugin\TcaPluginManager;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
class TcaPermissionGenerator implements ContainerInjectionInterface {
use StringTranslationTrait;
private $entityTypeManager = NULL;
private $tcaPluginManager = NULL;
public function __construct(EntityTypeManagerInterface $etm, TcaPluginManager $tca_plugin_manager, TranslationInterface $translation) {
$this->entityTypeManager = $etm;
$this->tcaPluginManager = $tca_plugin_manager;
$this->stringTranslation = $translation;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager'), $container
->get('plugin.manager.tca_plugin'), $container
->get('string_translation'));
}
public function permissions() {
$permissions = [];
foreach ($this->tcaPluginManager
->getDefinitions() as $def) {
$entity_type = $this->entityTypeManager
->getStorage($def['entityType'])
->getEntityType();
$permissions += [
'tca administer ' . $def['entityType'] => [
'title' => $this
->t('Administer Token Content Access settings for %entity_type', [
'%entity_type' => $entity_type
->getLabel(),
]),
],
'tca bypass ' . $def['entityType'] => [
'title' => $this
->t('Bypass Token Content Access action for %entity_type', [
'%entity_type' => $entity_type
->getLabel(),
]),
],
];
}
return $permissions;
}
}