class TransactionPermissions in Transaction 8
Provides dynamic permissions for transactions of different types.
Hierarchy
- class \Drupal\transaction\TransactionPermissions implements ContainerInjectionInterface uses StringTranslationTrait
Expanded class hierarchy of TransactionPermissions
File
- src/
TransactionPermissions.php, line 13
Namespace
Drupal\transactionView source
class TransactionPermissions implements ContainerInjectionInterface {
use StringTranslationTrait;
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* MediaPermissions constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager'));
}
/**
* Returns an array of transaction type permissions.
*
* @return array
* The transaction type permissions.
*
* @see \Drupal\user\PermissionHandlerInterface::getPermissions()
*/
public function transactionTypePermissions() {
$perms = [];
// Generate transaction permissions for all transaction types.
$transaction_types = $this->entityTypeManager
->getStorage('transaction_type')
->loadMultiple();
foreach ($transaction_types as $transaction_type) {
$perms += $this
->buildPermissions($transaction_type);
}
return $perms;
}
/**
* Returns a list of transaction permissions for a given transaction type.
*
* @param \Drupal\transaction\TransactionTypeInterface $type
* The transaction type.
*
* @return array
* An associative array of permission names and descriptions.
*/
protected function buildPermissions(TransactionTypeInterface $type) {
$type_id = $type
->id();
$type_params = [
'%type_name' => $type
->label(),
];
return [
"create {$type_id} transaction" => [
'title' => $this
->t('%type_name: Create new transaction', $type_params),
],
"view own {$type_id} transaction" => [
'title' => $this
->t('%type_name: View own transaction', $type_params),
],
"view any {$type_id} transaction" => [
'title' => $this
->t('%type_name: View any transaction', $type_params),
],
"edit own {$type_id} transaction" => [
'title' => $this
->t('%type_name: Edit own transaction', $type_params),
],
"edit any {$type_id} transaction" => [
'title' => $this
->t('%type_name: Edit any transaction', $type_params),
],
"delete own {$type_id} transaction" => [
'title' => $this
->t('%type_name: Delete own transaction', $type_params),
],
"delete any {$type_id} transaction" => [
'title' => $this
->t('%type_name: Delete any transaction', $type_params),
],
"execute own {$type_id} transaction" => [
'title' => $this
->t('%type_name: Execute own transaction', $type_params),
],
"execute any {$type_id} transaction" => [
'title' => $this
->t('%type_name: Execute any transaction', $type_params),
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
TransactionPermissions:: |
protected | property | The entity type manager service. | |
TransactionPermissions:: |
protected | function | Returns a list of transaction permissions for a given transaction type. | |
TransactionPermissions:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
TransactionPermissions:: |
public | function | Returns an array of transaction type permissions. | |
TransactionPermissions:: |
public | function | MediaPermissions constructor. |