ce0b28eaec302dc83f69949418a148608c4329e8
[yaffs-website] / vendor / drush / drush / lib / Drush / Role / Role8.php
1 <?php
2
3 namespace Drush\Role;
4
5 use Drupal\user\Entity\Role;
6
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);
18     }
19     $role = new Role(array(
20       'id' => $role_machine_name,
21       'label' => $role_human_readable_name,
22     ), 'user_role');
23     $role->save();
24     return $role;
25   }
26
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));
31     return $perms;
32   }
33
34   public function getAllModulePerms() {
35     $perms = \Drupal::service('user.permissions')->getPermissions();
36     return array_keys($perms);
37   }
38
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;
45       }
46     }
47     return $module_perms;
48   }
49
50   public function delete() {
51     $role = entity_load('user_role', $this->rid);
52     $role->delete();
53   }
54
55   public function grant_permissions($perms) {
56     return drush_op('user_role_grant_permissions', $this->rid, $perms);
57   }
58
59   public function revoke_permissions($perms) {
60     return drush_op('user_role_revoke_permissions', $this->rid, $perms);
61   }
62 }