Neos\Neos\Domain\Service\UserService::deleteUser PHP Method

deleteUser() public method

Deletes the specified user and all remaining content in his personal workspaces
public deleteUser ( User $user ) : void
$user Neos\Neos\Domain\Model\User The user to delete
return void
    public function deleteUser(User $user)
    {
        $backendUserRole = $this->policyService->getRole('Neos.Neos:AbstractEditor');
        foreach ($user->getAccounts() as $account) {
            /** @var Account $account */
            if ($account->hasRole($backendUserRole)) {
                $this->deletePersonalWorkspace($account->getAccountIdentifier());
            }
            $this->accountRepository->remove($account);
        }
        $this->removeOwnerFromUsersWorkspaces($user);
        $this->partyRepository->remove($user);
        $this->emitUserDeleted($user);
    }

Usage Example

 /**
  * Delete the given user
  *
  * @param User $user
  * @return void
  */
 public function deleteAction(User $user)
 {
     if ($user === $this->currentUser) {
         $this->addFlashMessage('You can not delete the currently logged in user', 'Current user can\'t be deleted', Message::SEVERITY_WARNING, array(), 1412374546);
         $this->redirect('index');
     }
     $this->userService->deleteUser($user);
     $this->addFlashMessage('The user "%s" has been deleted.', 'User deleted', Message::SEVERITY_NOTICE, array(htmlspecialchars($user->getName()->getFullName())), 1412374546);
     $this->redirect('index');
 }
All Usage Examples Of Neos\Neos\Domain\Service\UserService::deleteUser