diff --git a/core/modules/rest/src/Plugin/rest/resource/UserRegistrationResource.php b/core/modules/rest/src/Plugin/rest/resource/UserRegistrationResource.php index 30e1265..c0f97e2 100644 --- a/core/modules/rest/src/Plugin/rest/resource/UserRegistrationResource.php +++ b/core/modules/rest/src/Plugin/rest/resource/UserRegistrationResource.php @@ -10,6 +10,7 @@ use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\ContentEntityBase; +use Drupal\Core\Render\RenderContext; use Drupal\rest\ResourceResponse; use Drupal\user\Entity\User; use Psr\Log\LoggerInterface; @@ -128,18 +129,27 @@ public function post(User $account = NULL) { } $account->save(); + // Send emails from a render context to add bubbleable_metadata to the response. + $context = new RenderContext(); + $renderer = \Drupal::service('renderer'); + $renderer->executeInRenderContext($context, function() use ($account) { + // "Verify email" option disabled and the account as active means that the user can be logged in now. + if (!$this->configFactory->get('user.settings')->get('verify_mail') && $account->isActive()) { + _user_mail_notify('register_no_approval_required', $account); + user_login_finalize($account); + } + // The new account as blocked means that it needs approval. + elseif (!$account->isActive()) { + _user_mail_notify('register_pending_approval', $account); + } + }); - // "Verify email" option disabled and the account as active means that the user can be logged in now. - if (!$this->configFactory->get('user.settings')->get('verify_mail') && $account->isActive()) { - _user_mail_notify('register_no_approval_required', $account); - user_login_finalize($account); - } - // The new account as blocked means that it needs approval. - elseif (!$account->isActive()) { - _user_mail_notify('register_pending_approval', $account); + $response = new ResourceResponse(NULL, 201); + if (!$context->isEmpty()) { + $response->addCacheableDependency($context->pop()); } - return new ResourceResponse(NULL, 201); + return $response; } /** diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 4b4bd6f..422d0bf 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -1207,7 +1207,7 @@ function user_role_revoke_permissions($rid, array $permissions = array()) { * language. * * @return array - * An array containint various information about the message. + * An array containing various information about the message. * See \Drupal\Core\Mail\MailManagerInterface::mail() for details. * * @see user_mail_tokens()