ConnectionPermissions.php in RedHen CRM 8
File
modules/redhen_connection/src/ConnectionPermissions.php
View source
<?php
namespace Drupal\redhen_connection;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\redhen_connection\Entity\ConnectionType;
class ConnectionPermissions {
use StringTranslationTrait;
public function ConnectionTypePermissions() {
$perms = [];
foreach (ConnectionType::loadMultiple() as $type) {
$perms += $this
->buildPermissions($type);
}
$perms += $this
->buildListingPermissions();
return $perms;
}
protected function buildPermissions(ConnectionType $connection_type) {
$type_id = $connection_type
->id();
$type_params = [
'%type' => $connection_type
->label(),
];
return [
"add {$type_id} connection" => [
'title' => $this
->t('%type: Add connection', $type_params),
],
"view active {$type_id} connection" => [
'title' => $this
->t('%type: View active connections', $type_params),
],
"view inactive {$type_id} connection" => [
'title' => $this
->t('%type: View inactive connections', $type_params),
],
"edit {$type_id} connection" => [
'title' => $this
->t('%type: Edit connections', $type_params),
],
"delete {$type_id} connection" => [
'title' => $this
->t('%type: Delete connections', $type_params),
],
];
}
protected function buildListingPermissions() {
$permissions = [];
foreach (\Drupal::service('redhen_connection.connections')
->getAllConnectionEntityTypes() as $entity_type_id => $entity_type) {
if (!($path = $entity_type
->getLinkTemplate('redhen_connection'))) {
continue;
}
$permissions["view own active {$entity_type_id} connection"] = [
'title' => $this
->t('%type: View own active connections', [
'%type' => $entity_type
->getLabel(),
]),
];
}
return $permissions;
}
}