Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem
Setting notify to FALSE on "status_activated" doesn't block _user_mail_notify() to send the email.
function _user_mail_notify($op, $account, $langcode = NULL) {
// By default, we always notify except for canceled and blocked.
$notify = \Drupal::config('user.settings')->get('notify.' . $op);
if ($notify || ($op != 'status_canceled' && $op != 'status_blocked')) {
Proposed resolution
I think it lacks condition "&& $op != 'status_activated'" :
function _user_mail_notify($op, $account, $langcode = NULL) {
// By default, we always notify except for canceled and blocked.
$notify = \Drupal::config('user.settings')->get('notify.' . $op);
if ($notify || ($op != 'status_canceled' && $op != 'status_blocked' && $op != 'status_activated' )) {
How to reproduce
- Set notification to false on "account activation" on Administration > Configuration > People > Account settings
- Set user.settings.notify.status_activated FALSE
- Block user
- Activate user
Comment | File | Size | Author |
---|---|---|---|
#2 | drupal-core-user-notify-2770369-1.patch | 1.36 KB | ozin |
Comments
Comment #2
ozinHi @djidane35
Please check my patch if it works for you. Thanks.
Comment #3
smazI've just tested the patch in #2 by doing the following:
drush config-set user.settings notify.status_activated 0
I received the activation email.
After the patch, I re-blocked & re-activated the user, and this time didn't receive the email notification.
The patch looks fine code wise, too.
However, does this need an automated test? I can see that there are tests currently that set notification settings etc., but as there currently isn't a test for activating a user I'm not sure if one is needed or what to start with.
Cheers
Comment #4
ozinHi @smaz, thanks for your testing. Regarding Automated tests, I think we do not need it since it is not a new functionality or feature.
Comment #5
markdorison@ozin, I believe @smaz is correct; this is going to need a test.
Comment #6
ozinOk, then I will add tests as soon as possible.
Comment #7
djidane35 CreditAttribution: djidane35 commentedHi, in my opinion this kind of fix is not sustainable over time.
For example, in the future, if a notification is deactivale for another operation, it will think about going to add the operation into the array $configurable_ops.
I think we should handle this with a global configuration to be effective.
Comment #8
lhangea CreditAttribution: lhangea commentedComment #9
ozin