class RabbitHolePermissionGenerator in Rabbit Hole 2.x
Same name and namespace in other branches
- 8 src/RabbitHolePermissionGenerator.php \Drupal\rabbit_hole\RabbitHolePermissionGenerator
Generates permission for each supported entity type.
Hierarchy
- class \Drupal\rabbit_hole\RabbitHolePermissionGenerator implements ContainerInjectionInterface uses StringTranslationTrait
Expanded class hierarchy of RabbitHolePermissionGenerator
File
- src/
RabbitHolePermissionGenerator.php, line 15
Namespace
Drupal\rabbit_holeView source
class RabbitHolePermissionGenerator implements ContainerInjectionInterface {
use StringTranslationTrait;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Entity plugin manager.
*
* @var \Drupal\rabbit_hole\Plugin\RabbitHoleEntityPluginManager
*/
protected $rhEntityPluginManager;
/**
* Constructor.
*/
public function __construct(EntityTypeManagerInterface $etm, RabbitHoleEntityPluginManager $entity_plugin_manager, TranslationInterface $translation) {
$this->entityTypeManager = $etm;
$this->rhEntityPluginManager = $entity_plugin_manager;
$this->stringTranslation = $translation;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager'), $container
->get('plugin.manager.rabbit_hole_entity_plugin'), $container
->get('string_translation'));
}
/**
* Return an array of per-entity rabbit hole permissions.
*
* @return array
* An array of permissions.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
public function permissions() {
$permissions = [];
foreach ($this->rhEntityPluginManager
->getDefinitions() as $def) {
$entity_type = $this->entityTypeManager
->getStorage($def['entityType'])
->getEntityType();
$permissions += [
'rabbit hole administer ' . $def['entityType'] => [
'title' => $this
->t('Administer Rabbit Hole settings for %entity_type', [
'%entity_type' => $entity_type
->getLabel(),
]),
],
'rabbit hole bypass ' . $def['entityType'] => [
'title' => $this
->t('Bypass Rabbit Hole action for %entity_type', [
'%entity_type' => $entity_type
->getLabel(),
]),
],
];
}
return $permissions;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RabbitHolePermissionGenerator:: |
protected | property | The entity type manager. | |
RabbitHolePermissionGenerator:: |
protected | property | Entity plugin manager. | |
RabbitHolePermissionGenerator:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
RabbitHolePermissionGenerator:: |
public | function | Return an array of per-entity rabbit hole permissions. | |
RabbitHolePermissionGenerator:: |
public | function | Constructor. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |