function UserRegistrationResource::post

Same name and namespace in other branches
  1. 8.9.x core/modules/user/src/Plugin/rest/resource/UserRegistrationResource.php \Drupal\user\Plugin\rest\resource\UserRegistrationResource::post()
  2. 10 core/modules/user/src/Plugin/rest/resource/UserRegistrationResource.php \Drupal\user\Plugin\rest\resource\UserRegistrationResource::post()
  3. 11.x core/modules/user/src/Plugin/rest/resource/UserRegistrationResource.php \Drupal\user\Plugin\rest\resource\UserRegistrationResource::post()

Responds to user registration POST request.

Parameters

\Drupal\user\UserInterface $account: The user account entity.

Return value

\Drupal\rest\ModifiedResourceResponse The HTTP response object.

Throws

\Symfony\Component\HttpKernel\Exception\BadRequestHttpException

\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException

File

core/modules/user/src/Plugin/rest/resource/UserRegistrationResource.php, line 100

Class

UserRegistrationResource
Represents user registration as a resource.

Namespace

Drupal\user\Plugin\rest\resource

Code

public function post(UserInterface $account = NULL) {
    $this->ensureAccountCanRegister($account);
    // Only activate new users if visitors are allowed to register and no email
    // verification required.
    if ($this->userSettings
        ->get('register') == UserInterface::REGISTER_VISITORS && !$this->userSettings
        ->get('verify_mail')) {
        $account->activate();
    }
    else {
        $account->block();
    }
    $this->checkEditFieldAccess($account);
    // Make sure that the user entity is valid (email and name are valid).
    $this->validate($account);
    // Create the account.
    $account->save();
    $this->sendEmailNotifications($account);
    return new ModifiedResourceResponse($account, 200);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.