5 use Drupal\user\Entity\Role;
7 class Role8 extends Role7 {
8 public function role_create($role_machine_name, $role_human_readable_name = '') {
9 // In D6 and D7, when we create a new role, the role
10 // machine name is specified, and the numeric rid is
11 // auto-assigned (next available id); in D8, when we
12 // create a new role, we need to specify both the rid,
13 // which is now the role machine name, and also a human-readable
14 // role name. If the client did not provide a human-readable
15 // name, then we'll use the role machine name in its place.
16 if (empty($role_human_readable_name)) {
17 $role_human_readable_name = ucfirst($role_machine_name);
19 $role = new Role(array(
20 'id' => $role_machine_name,
21 'label' => $role_human_readable_name,
27 public function getPerms() {
28 $role = entity_load('user_role', $this->rid);
29 $perms = $role->getPermissions();
30 // $perms = user_role_permissions(array($this->rid => $this->name));
34 public function getAllModulePerms() {
35 $perms = \Drupal::service('user.permissions')->getPermissions();
36 return array_keys($perms);
39 public function getModulePerms($module) {
40 $module_perms = array();
41 $perms = \Drupal::service('user.permissions')->getPermissions();
42 foreach ($perms as $name => $perm) {
43 if ($perm['provider'] == $module) {
44 $module_perms[] = $name;
50 public function delete() {
51 $role = entity_load('user_role', $this->rid);
55 public function grant_permissions($perms) {
56 return drush_op('user_role_grant_permissions', $this->rid, $perms);
59 public function revoke_permissions($perms) {
60 return drush_op('user_role_revoke_permissions', $this->rid, $perms);