public function create(
        $limit
    ) {
        $roles = [];
        for ($i = 0; $i < $limit; $i++) {
            try {
                $rolename = $this->getRandom()->word(mt_rand(6, 12));

                $role = $this->entityTypeManager->getStorage('user_role')->create(
                    [
                        'id' => $rolename,
                        'label' => $rolename,
                        'originalId' => $rolename
                    ]
                );

                $role->save();

                $roles['success'][] = [
                    'role-id' => $role->id(),
                    'role-name' => $role->get('label')
                ];
            } catch (\Exception $error) {
                $roles['error'][] = $error->getMessage();
            }
        }

        return $roles;
    }
public function create(
        $limit
    ) {
        $roles = [];
        for ($i = 0; $i < $limit; $i++) {
            try {
                $rolename = $this->getRandom()->word(mt_rand(6, 12));

                $role = $this->entityTypeManager->getStorage('user_role')->create(
                    [
                        'id' => $rolename,
                        'label' => $rolename,
                        'originalId' => $rolename
                    ]
                );

                $role->save();

                $roles['success'][] = [
                    'role-id' => $role->id(),
                    'role-name' => $role->get('label')
                ];
            } catch (\Exception $error) {
                $roles['error'][] = $error->getMessage();
            }
        }

        return $roles;
    }
public function create ( $ limit ) { $ roles = [ ] ; for ( $ i = 0 ; $ i < $ limit ; $ i ++ ) { try { $ rolename = $ this -> getRandom ( ) -> word ( mt_rand ( 6 , 12 ) ) ; $ role = $ this -> entityTypeManager -> getStorage ( 'user_role' ) -> create ( [ 'id' => $ rolename , 'label' => $ rolename , 'originalId' => $ rolename ] ) ; $ role -> save ( ) ; $ roles [ 'success' ] [ ] = [ 'role-id' => $ role -> id ( ) , 'role-name' => $ role -> get ( 'label' ) ] ; } catch ( \ Exception $ error ) { $ roles [ 'error' ] [ ] = $ error -> getMessage ( ) ; } } return $ roles ; }
Create and returns an array of new Roles.

@param $limit

@return array
Create and returns an array of new Roles .