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.

Issue fork drupal-3002019

Command icon 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:

Comments

hanoii created an issue. See original summary.

hanoii’s picture

Issue summary: View changes
hanoii’s picture

StatusFileSize
new1.03 KB

Removing the verify_email validation. Drupal sends the email regardless, so should the rest resource.

hanoii’s picture

Status: Active » Needs review
cilefen’s picture

Title: Register an without email verification should still send an email » Register a user without email verification should still send an email

Status: Needs review » Needs work

The last submitted patch, 3: 3002019-n3.patch, failed testing. View results

hanoii’s picture

Status: Needs work » Needs review
StatusFileSize
new1.69 KB

The 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.

wim leers’s picture

Component: rest.module » user system
Issue tags: +API-First Initiative

Thanks for reporting this! Moving to the user.module issue queue, since this is a @RestResource plugin provided by that module.

wim leers’s picture

Component: user system » user.module

Oops!

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

hanoii’s picture

StatusFileSize
new1.72 KB

Re-rolled against latest code, both 8.8.xx and 8.7.x now works.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

raphael apard’s picture

Seems to be fixed on 9.x

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

giuseppe87’s picture

StatusFileSize
new1.09 KB

I've uploaded a version for 9.4.x, as it seems still necessary for my site.

smustgrave’s picture

Status: Needs review » Needs work

Moving back to needs work as the patch #19 does not apply. And for testing need updated testing steps.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

giuseppe87’s picture

#19 still applies on D9.5.x and it works.

rpayanm made their first commit to this issue’s fork.

rpayanm’s picture

Trying to fix the Custom Commands Failed.

smustgrave’s picture

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

pierostz’s picture

#19 applies to Drupal 10.3.10 and works.

dcam made their first commit to this issue’s fork.

dcam changed the visibility of the branch 11.x to hidden.

dcam changed the visibility of the branch 3002019-10.1.x to hidden.

joshua1234511’s picture

Issue summary: View changes
Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs tests, -Needs issue summary update

Tested 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,

  • catch committed 45f78be8 on 11.2.x
    Issue #3002019 by hanoii, dcam, rpayanm, giuseppe87: Register a user...

  • catch committed a1bc1b39 on 11.x
    Issue #3002019 by hanoii, dcam, rpayanm, giuseppe87: Register a user...
catch’s picture

Version: 11.x-dev » 11.2.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x and cherry-picked to 11.2.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.