You are here

public function ContactPermissionsPermissions::permissions in Contact Permissions 8.2

Same name and namespace in other branches
  1. 8 src/ContactPermissionsPermissions.php \Drupal\contact_permissions\ContactPermissionsPermissions::permissions()

Get access per role contact forms permissions.

Return value

array Permissions array.

1 string reference to 'ContactPermissionsPermissions::permissions'
contact_permissions.permissions.yml in ./contact_permissions.permissions.yml
contact_permissions.permissions.yml

File

src/ContactPermissionsPermissions.php, line 20

Class

ContactPermissionsPermissions
Provides the permissions for accessing per role contact forms.

Namespace

Drupal\contact_permissions

Code

public function permissions() {

  // Generate permissions for each user role.
  $permissions = [];

  /* @var \Drupal\user\RoleInterface[] $roles */
  $roles = user_roles(TRUE);
  if (count($roles) < 1) {
    return $permissions;
  }
  foreach ($roles as $role) {
    $role_name = $role
      ->label();
    $role_id = $role
      ->id();
    $permissions["use {$role_id} personal contact forms"] = [
      'title' => $this
        ->t("Use %role_name's personal contact forms", [
        '%role_name' => $role_name,
      ]),
    ];
  }
  return $permissions;
}