public function QaAccountsCreateDelete::deleteQaAccountForRole in QA Accounts 8
Deletes QA account for specified role.
Parameters
string $role_name: The machine name of the role the account is to be deleted for.
Overrides QaAccountsCreateDeleteInterface::deleteQaAccountForRole
1 call to QaAccountsCreateDelete::deleteQaAccountForRole()
- QaAccountsCreateDelete::deleteQaAccounts in src/
QaAccountsCreateDelete.php - Deletes QA accounts.
File
- src/
QaAccountsCreateDelete.php, line 105
Class
- QaAccountsCreateDelete
- Service that creates and deletes QA accounts for roles.
Namespace
Drupal\qa_accountsCode
public function deleteQaAccountForRole($role_name) {
$username = 'qa_' . $role_name;
// Check that user for role exists.
$users = $this->entityTypeManager
->getStorage('user')
->loadByProperties([
'name' => $username,
]);
$user = $users ? reset($users) : NULL;
if ($user) {
$user
->delete();
$this->logger
->notice('Deleted user @name.', [
'@name' => $username,
]);
}
else {
$this->logger
->notice('No such user @name.', [
'@name' => $username,
]);
}
}