I believe this being a follow up to #2291055: REST resources for anonymous users: register.
When registering a user via the UserRegistrationResource REST endpoint, with email verification disabled (verify_mail = FALSE) and no administrative approval required the expected register_no_approval_required email notification is not sent.
In contrast, when registering a user via the Drupal UI under the same configuration and as an anonymous user, the register_no_approval_required notification is sent as expected.
This inconsistency suggests that the REST resource is not aligning with the intended behavior implemented in the RegisterForm logic.
I am creating an user with the rest resource, configured not to verify email address, and the register_no_approval_required is not sent.
However, registering the user with the same settings through the drupal UI as an anonymous user does send the notification.
One would expect the same behavior:
./core/modules/user/src/RegisterForm.php
<?php
// No email verification required; log in user immediately.
elseif (!$admin && !\Drupal::config('user.settings')->get('verify_mail') && $account->isActive()) {
_user_mail_notify('register_no_approval_required', $account);
user_login_finalize($account);
drupal_set_message($this->t('Registration successful. You are now logged in.'));
$form_state->setRedirect('<front>');
}
?>
./core/modules/user/src/Plugin/rest/resource/UserRegistrationResource.php:
<?php
protected function sendEmailNotifications(UserInterface $account) {
$approval_settings = $this->userSettings->get('register');
// No e-mail verification is required. Activating the user.
if ($approval_settings == USER_REGISTER_VISITORS) {
if ($this->userSettings->get('verify_mail')) {
// No administrator approval required.
_user_mail_notify('register_no_approval_required', $account);
}
}
// Administrator approval required.
elseif ($approval_settings == USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL) {
_user_mail_notify('register_pending_approval', $account);
}
}
?>
Steps to Reproduce
Set the following user settings in Drupal:
- Who can register accounts? → Visitors
- Require email verification → Disabled
Enable the User Registration REST resource and allow anonymous access.
Perform a POST request to /user/register via REST to create a new user.
Observe that:
- The user is created and marked active.
- No email is sent to the user (register_no_approval_required not triggered).
Now, go to the Drupal frontend and register a user with the same configuration.
The expected email is sent.
| Comment | File | Size | Author |
|---|---|---|---|
| #19 | 3002019-19.patch | 1.09 KB | giuseppe87 |
| #11 | 3002019-n11.patch | 1.72 KB | hanoii |
Issue fork drupal-3002019
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3002019-10.1.x
changes, plain diff MR !3984
- 3002019-user-rest-register-email
changes, plain diff MR !12288
- 11.x
compare
Comments
Comment #2
hanoiiComment #3
hanoiiRemoving the verify_email validation. Drupal sends the email regardless, so should the rest resource.
Comment #4
hanoiiComment #5
cilefen commentedComment #7
hanoiiThe fact that there was a test implies this was on purpose, however, I still believe it shouldn't be the case and still match the same behavior as non-rest.
Same patch with the modified test.
Comment #8
wim leersThanks for reporting this! Moving to the
user.moduleissue queue, since this is a@RestResourceplugin provided by that module.Comment #9
wim leersOops!
Comment #11
hanoiiRe-rolled against latest code, both 8.8.xx and 8.7.x now works.
Comment #16
raphael apard commentedSeems to be fixed on 9.x
Comment #19
giuseppe87 commentedI've uploaded a version for 9.4.x, as it seems still necessary for my site.
Comment #20
smustgrave commentedMoving back to needs work as the patch #19 does not apply. And for testing need updated testing steps.
Comment #22
giuseppe87 commented#19 still applies on D9.5.x and it works.
Comment #25
rpayanmTrying to fix the Custom Commands Failed.
Comment #26
smustgrave commentedComment #28
pierostz commented#19 applies to Drupal 10.3.10 and works.
Comment #33
joshua1234511Tested the patch https://git.drupalcode.org/project/drupal/-/merge_requests/12288.patch
Works as expected email is send.
Test has been updated to reflect the changes,
Comment #36
catchCommitted/pushed to 11.x and cherry-picked to 11.2.x, thanks!