public function Role8::role_create

8.0.x Role8.php public Role8::role_create($role_machine_name, $role_human_readable_name = '')
7.x Role8.php public Role8::role_create($role_machine_name, $role_human_readable_name = '')
master Role8.php public Role8::role_create($role_machine_name, $role_human_readable_name = '')

Overrides Role7::role_create

File

lib/Drush/Role/Role8.php, line 8

Namespace

Drush\Role

Class

Role8

Code

public function role_create($role_machine_name, $role_human_readable_name = '') {
  // In D7, when we create a new role, the role
  // machine name is specified, and the numeric rid is
  // auto-assigned (next available id); in D8, when we
  // create a new role, we need to specify both the rid,
  // which is now the role machine name, and also a human-readable
  // role name.  If the client did not provide a human-readable
  // name, then we'll use the role machine name in its place.
  if (empty($role_human_readable_name)) {
    $role_human_readable_name = ucfirst($role_machine_name);
  }
  $role = new Role(array(
    'id' => $role_machine_name,
    'label' => $role_human_readable_name,
  ), 'user_role');
  $role->save();
  return $role;
}