ContactPermissions.php in RedHen CRM 8
File
modules/redhen_contact/src/ContactPermissions.php
View source
<?php
namespace Drupal\redhen_contact;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\redhen_contact\Entity\ContactType;
class ContactPermissions {
use StringTranslationTrait;
public function ContactTypePermissions() {
$perms = [];
foreach (ContactType::loadMultiple() as $type) {
$perms += $this
->buildPermissions($type);
}
return $perms;
}
protected function buildPermissions(ContactType $contact_type) {
$type_id = $contact_type
->id();
$type_params = [
'%type' => $contact_type
->label(),
];
return [
"add {$type_id} contact" => [
'title' => $this
->t('%type: Add contact', $type_params),
],
"view active {$type_id} contact" => [
'title' => $this
->t('%type: View active contacts', $type_params),
],
"view inactive {$type_id} contact" => [
'title' => $this
->t('%type: View inactive contacts', $type_params),
],
"view own {$type_id} contact" => [
'title' => $this
->t('%type: View own (active) contact', $type_params),
],
"edit own {$type_id} contact" => [
'title' => $this
->t('%type: Edit own contact', $type_params),
],
"edit any {$type_id} contact" => [
'title' => $this
->t('%type: Edit any contact', $type_params),
],
"delete own {$type_id} contact" => [
'title' => $this
->t('%type: Delete own contact', $type_params),
],
"delete any {$type_id} contact" => [
'title' => $this
->t('%type: Delete any contact', $type_params),
],
];
}
}