You are here

public function CancelUserAction::execute in Views Bulk Operations (VBO) 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/Action/CancelUserAction.php \Drupal\views_bulk_operations\Plugin\Action\CancelUserAction::execute()
  2. 8 src/Plugin/Action/CancelUserAction.php \Drupal\views_bulk_operations\Plugin\Action\CancelUserAction::execute()
  3. 4.0.x src/Plugin/Action/CancelUserAction.php \Drupal\views_bulk_operations\Plugin\Action\CancelUserAction::execute()

Executes the plugin.

Overrides ExecutableInterface::execute

File

src/Plugin/Action/CancelUserAction.php, line 93

Class

CancelUserAction
Cancels a user account.

Namespace

Drupal\views_bulk_operations\Plugin\Action

Code

public function execute($account = NULL) {
  if ($account
    ->id() === $this->currentUser
    ->id() && (empty($this->context['list']) || count($this->context['list'] > 1))) {
    drupal_set_message($this
      ->t('The current user account cannot be canceled in a batch operation. Select your account only or cancel it from your account page.'), 'error');
  }
  elseif (intval($account
    ->id()) === 1) {
    drupal_set_message($this
      ->t('The user 1 account (%label) cannot be canceled.', [
      '%label' => $account
        ->label(),
    ]), 'error');
  }
  else {

    // Allow other modules to act.
    if ($this->configuration['user_cancel_method'] != 'user_cancel_delete') {
      $this->moduleHandler
        ->invokeAll('user_cancel', [
        $this->configuration,
        $account,
        $this->configuration['user_cancel_method'],
      ]);
    }

    // Cancel the account.
    _user_cancel($this->configuration, $account, $this->configuration['user_cancel_method']);

    // If current user was cancelled, logout.
    if ($account
      ->id() == $this->currentUser
      ->id()) {
      _user_cancel_session_regenerate();
    }
  }
}