You are here

protected function UserBlock::doExecute in Rules 8.3

Block a user.

Parameters

\Drupal\user\UserInterface $user: The user object.

File

src/Plugin/RulesAction/UserBlock.php, line 79

Class

UserBlock
Provides "Block User" action.

Namespace

Drupal\rules\Plugin\RulesAction

Code

protected function doExecute(UserInterface $user) {

  // Do nothing if user is anonymous or already blocked.
  if ($user
    ->isAuthenticated() && $user
    ->isActive()) {
    $user
      ->block();
    $this->sessionManager
      ->delete($user
      ->id());

    // Set flag that indicates if the entity should be auto-saved later.
    $this->saveLater = TRUE;
  }
}