View source
<?php
namespace Drupal\transaction;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
class TransactionPermissions implements ContainerInjectionInterface {
use StringTranslationTrait;
protected $entityTypeManager;
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager'));
}
public function transactionTypePermissions() {
$perms = [];
$transaction_types = $this->entityTypeManager
->getStorage('transaction_type')
->loadMultiple();
foreach ($transaction_types as $transaction_type) {
$perms += $this
->buildPermissions($transaction_type);
}
return $perms;
}
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),
],
];
}
}