class ScheduledTransitionsPermissions in Scheduled Transitions 8
Same name and namespace in other branches
- 2.x src/ScheduledTransitionsPermissions.php \Drupal\scheduled_transitions\ScheduledTransitionsPermissions
Generates permissions for host entity types for scheduled transitions.
Hierarchy
- class \Drupal\scheduled_transitions\ScheduledTransitionsPermissions implements ContainerInjectionInterface uses StringTranslationTrait
Expanded class hierarchy of ScheduledTransitionsPermissions
9 files declare their use of ScheduledTransitionsPermissions
- ScheduledTransitionEntityTransitionsFormTest.php in tests/
src/ Functional/ ScheduledTransitionEntityTransitionsFormTest.php - ScheduledTransitionModalFormTest.php in tests/
src/ Functional/ ScheduledTransitionModalFormTest.php - ScheduledTransitionRescheduleFormTest.php in tests/
src/ Functional/ ScheduledTransitionRescheduleFormTest.php - ScheduledTransitionsEntityHooks.php in src/
ScheduledTransitionsEntityHooks.php - ScheduledTransitionsEntityHooksUnitTest.php in tests/
src/ Unit/ ScheduledTransitionsEntityHooksUnitTest.php
File
- src/
ScheduledTransitionsPermissions.php, line 17
Namespace
Drupal\scheduled_transitionsView source
class ScheduledTransitionsPermissions implements ContainerInjectionInterface {
use StringTranslationTrait;
/**
* Entity operation for viewing transitions for an individual entity.
*/
public const ENTITY_OPERATION_VIEW_TRANSITIONS = 'view scheduled transition';
/**
* Entity operation for adding transitions to an individual entity.
*/
public const ENTITY_OPERATION_ADD_TRANSITION = 'add scheduled transition';
/**
* Entity operation for rescheduling all transitions for an individual entity.
*/
public const ENTITY_OPERATION_RESCHEDULE_TRANSITIONS = 'reschedule scheduled transitions';
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The bundle information service.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $bundleInfo;
/**
* Utilities for Scheduled Transitions module.
*
* @var \Drupal\scheduled_transitions\ScheduledTransitionsUtilityInterface
*/
protected $scheduledTransitionsUtility;
/**
* Constructs a new ScheduledTransitionsPermissions.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $bundleInfo
* The bundle information service.
* @param \Drupal\Core\StringTranslation\TranslationInterface $stringTranslation
* The string translation service.
* @param \Drupal\scheduled_transitions\ScheduledTransitionsUtilityInterface $scheduledTransitionsUtility
* Utilities for Scheduled Transitions module.
*/
public function __construct(EntityTypeManagerInterface $entityTypeManager, EntityTypeBundleInfoInterface $bundleInfo, TranslationInterface $stringTranslation, ScheduledTransitionsUtilityInterface $scheduledTransitionsUtility) {
$this->entityTypeManager = $entityTypeManager;
$this->bundleInfo = $bundleInfo;
$this->stringTranslation = $stringTranslation;
$this->scheduledTransitionsUtility = $scheduledTransitionsUtility;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager'), $container
->get('entity_type.bundle.info'), $container
->get('string_translation'), $container
->get('scheduled_transitions.utility'));
}
/**
* Generate dynamic permissions.
*
* @return array
* An array of permissions.
*/
public function permissions() : array {
$permissions = [];
$bundleInfo = $this->scheduledTransitionsUtility
->getBundles();
foreach ($bundleInfo as $entityTypeId => $bundles) {
$entityBundleInfo = $this->bundleInfo
->getBundleInfo($entityTypeId);
foreach ($bundles as $bundleId) {
$tArgs = [
'@entity_type' => $this->entityTypeManager
->getDefinition($entityTypeId)
->getLabel(),
'@bundle' => $entityBundleInfo[$bundleId]['label'] ?? '',
];
$viewPermission = static::viewScheduledTransitionsPermission($entityTypeId, $bundleId);
$permissions[$viewPermission] = [
'title' => $this
->t('View scheduled transitions for @entity_type:@bundle entities', $tArgs),
];
$addPermission = static::addScheduledTransitionsPermission($entityTypeId, $bundleId);
$permissions[$addPermission] = [
'title' => $this
->t('Add scheduled transitions for @entity_type:@bundle entities', $tArgs),
];
$reschedulePermission = static::rescheduleScheduledTransitionsPermission($entityTypeId, $bundleId);
$permissions[$reschedulePermission] = [
'title' => $this
->t('Reschedule scheduled transitions for @entity_type:@bundle entities', $tArgs),
];
}
}
return $permissions;
}
/**
* Creates a permission for viewing new scheduled transitions for a bundle.
*
* @param string $entityTypeId
* An entity type ID.
* @param string $bundle
* A bundle ID.
*
* @return string
* Permission ID for this bundle.
*/
public static function viewScheduledTransitionsPermission(string $entityTypeId, string $bundle) : string {
return sprintf('view scheduled transitions %s %s', $entityTypeId, $bundle);
}
/**
* Creates a permission for creating new scheduled transitions for a bundle.
*
* @param string $entityTypeId
* An entity type ID.
* @param string $bundle
* A bundle ID.
*
* @return string
* Permission ID for this bundle.
*/
public static function addScheduledTransitionsPermission(string $entityTypeId, string $bundle) : string {
return sprintf('add scheduled transitions %s %s', $entityTypeId, $bundle);
}
/**
* Creates a permission for rescheduling scheduled transitions for a bundle.
*
* @param string $entityTypeId
* An entity type ID.
* @param string $bundle
* A bundle ID.
*
* @return string
* Permission ID for this bundle.
*/
public static function rescheduleScheduledTransitionsPermission(string $entityTypeId, string $bundle) : string {
return sprintf('reschedule scheduled transitions %s %s', $entityTypeId, $bundle);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ScheduledTransitionsPermissions:: |
protected | property | The bundle information service. | |
ScheduledTransitionsPermissions:: |
protected | property | The entity type manager. | |
ScheduledTransitionsPermissions:: |
protected | property | Utilities for Scheduled Transitions module. | |
ScheduledTransitionsPermissions:: |
public static | function | Creates a permission for creating new scheduled transitions for a bundle. | |
ScheduledTransitionsPermissions:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
ScheduledTransitionsPermissions:: |
public | constant | Entity operation for adding transitions to an individual entity. | |
ScheduledTransitionsPermissions:: |
public | constant | Entity operation for rescheduling all transitions for an individual entity. | |
ScheduledTransitionsPermissions:: |
public | constant | Entity operation for viewing transitions for an individual entity. | |
ScheduledTransitionsPermissions:: |
public | function | Generate dynamic permissions. | |
ScheduledTransitionsPermissions:: |
public static | function | Creates a permission for rescheduling scheduled transitions for a bundle. | |
ScheduledTransitionsPermissions:: |
public static | function | Creates a permission for viewing new scheduled transitions for a bundle. | |
ScheduledTransitionsPermissions:: |
public | function | Constructs a new ScheduledTransitionsPermissions. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
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. |