Closed (duplicate)
Project:
User registration password
Version:
2.0.x-dev
Component:
Code
Priority:
Critical
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
9 Aug 2024 at 20:09 UTC
Updated:
3 Jun 2026 at 14:49 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
juandels3 commentedThe same error happened to me. When downgrading to version 2.0.1 the error is not reproduced.
Comment #3
dercheffeSame Issue here. IMO this is a major or even critical bug because it breaks user experience massively
Comment #4
megakeegman commentedGlad to find this issue, as I was also about to report it. It doesn't look like there is any reason this function needs to return an array, since the results are not actually used for anything besides to check if the array returned is empty. Additionally, I can see where some of the confusion is coming from. The mail function, run on line 622 of the .module, is documented to return a bool. However, the implementation that I am seeing from my current site's mailer, which is called in the MailManagerReplacement class of the symfony_mailer contrib module, returns an array. So there seems to be a lot of confusion even deeper around whether or not we should be dealing with an array or a bool. I am not sure yet where exactly this confusion stems from, whether this a core change that contrib modules haven't caught up with or whether there are just a few implementations doing it wrong. My best guess so far is that everything should be moving in the direction of the mail function returning a bool, and then any of the code that does anything with the result of the mail function should be updated accordingly. Of course ensuring that our mailers are implementing the mail function correctly. There is also the possibility that the mail function is just documented incorrectly. If anyone has any background knowledge on this, that would be great.
Comment #5
megakeegman commentedFor what it's worth, the MailInterface class in Drupal core hasn't been touched for 3 years, and indicates that the mail function should return a bool, see https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co...
as well as the core symfony mailer implementation https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co...
And indeed, the relevant issue in symfony_mailer (contrib, not what's in core) about its implementation returning a value of the wrong type (array): https://www.drupal.org/project/symfony_mailer/issues/3400070
So yeah... Those are the clues we have to work with.
The spaghetti coder in me says handle both scenarios by having user_registrationpassword_mail_notify return either $mail or $mail['result'] depending on whether $mail is an array or a boolean. The module maintainer in me says don't spaghetti code. But either way have the return value of user_registrationpassword_mail_notify be a boolean, not an array. and wherever the result of this function is stored, update any logic to that touches it to handle the boolean as well.
Comment #6
sadix_selah commentedI have a quick because I don't enaough time to think it through :
$mail = \Drupal::service('plugin.manager.mail')->mail('user_registrationpassword', $op, $account->getEmail(), $langcode, $params, $site_mail);
//$output = $mail['result'] ?? [];
$output = $mail['result'] ? $mail : [];
Comment #7
megakeegman commentedUnfortunately, that won't work in the cases where $mail contains a boolean, which I think it should. But I'd really like to hear a maintainers thoughts on how they want to handle this, and if there is any history behind this.
Comment #8
megakeegman commentedI created a simple patch, which should work for anyone using a mailer that incorrectly implements the mail function, like the symfony_mailer contrib module. If you are using another mailer that correctly implements the mail function, and the mail function returns a boolean as per the Drupal core mail interface, then this patch is not for you.
With that being said, it should be pretty easy to re-patch for that, and I think that patch should also exist.
If someone wants or needs this, I think you just need to change
to
Unfortunately I don't have a list of which mailer modules do what.
Comment #9
jeremyskinner commentedWe've also run into this issue, which is causing our CI to fail. We've rolled back to 2.0.1 for now. Any chance of getting a new release with a fix for this as it breaks on all versions of Drupal 10 out of the box with no custom mail modules installed.
Comment #10
megakeegman commentedComment #12
grimreaperComment #14
grimreaperHere is the patch from MR for Composer usage.
I got to the same conclusions of @megakeegman.
MR is a slightly more advanced to handle cases.
Thanks for the review.
Comment #15
noah commentedWe're using Mailgun to send email, and we're seeing the problem both with and without the patch because the Mailgun module returns
Mailgun\Model\Message\SendResponserather than an array or a boolean. I looked for documentation to see if there's a “right” type for$return['result'], but couldn't find anything. I did find that the email_contact module dealt with the same issue just by checking if$return['result']is empty rather than expecting a specific type:https://www.drupal.org/project/email_contact/issues/3468210
Would that be a reasonable option here?
Comment #16
umit+1 The same problem was observed on our sites
Comment #17
noah commentedI've updated the MR to check if
$mail['return']is empty, rather than expecting a specific type, which should make it more flexible and compatible with, e.g. the Mailgun module. Updated patch attached.Comment #18
gorkagr commentedSame error making the site a bit unusable for us (at least is local and we did not deploy it yet).
MR works fine.
Best
Comment #19
gorkagr commentedComment #20
thirstysix commented#17 works fine with D10.3.x
Comment #21
muaz7731+1 for RTBC patch #17
Comment #22
ankitv18 commentedLeft a comment ~~ moving into NW
Comment #24
vladimirausBased on mail() function documentation, it only can return an array.
Please review.
Comment #25
megakeegman commentedI did not recognize that there was a difference between MailManagerInterface and MailInterface: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Mail%21Ma...
So the mail function on MailInterface returns a bool, while the one on MailManagerInterface returns an array. And MailInterface->mail() "sends message composed by MailManagerInterface->mail()"
Comment #26
coretex commentedThe issue is fixed with the last MR changes from VladimirAus.
Comment #27
andrew answer commentedHi,
I debugged the problem and find out that Drupal return 1 (just 1) from mail() function, so I replace null coalescing operator with its equivalent isset() according to PHP documentation, and add array [] to the first option (see patch).
The bug is gone. D10.3.10, user_registrationpassword 2.0.2.
Comment #28
elusivemind commentedI think this will work. But since the calling function on 339 doesn't care about a return value and 554 is just looking for a value, should the return of the function be a bool and the returns refactored accordingly? Happy to do it, but thought it may be a better way to go.
Comment #29
elusivemind commentedPatch #17 worked for me on v2.0.2 and drupal 11.0.9
It is also, in my opinion, the correct way to fix this. Verified working.
Comment #30
ron collins commentedThe patch in #17 is working for m as well.
Comment #31
ron collins commentedComment #32
phannphong commentedThe patch #17 works like a charm. Thank you!
Comment #33
coretex commentedA lot of people are saying patch from 17 works and different people have commited changes as patches and the merge request. Which one will be merged? Can one of the module maintainers merge this and make a new release?
Comment #35
oily commentedFixed PHPCS.
Comment #36
oily commentedThere are unresolved comments in the MR. These need to be resolved before this can be reviewed.
The edits to the gitlab pipeline file should probably be done in a follow-up. It is not clear what relationship they have to the issue.
Comment #38
oily commented@shivam_tiwari I have added 2 more comments. Seems you made 2x changes that were unnecessary, I suggest you revert those changes. Then PHPCS should pass. Once that happens the pipeline will progress to the tests and we can see if the tests are passing.
Comment #39
shivam_tiwari commented@oily Sorry for that, Firstly I updated MR according to the comments on the MR. Now I reverted the code according to you. Thanks for your quick response.
Comment #40
oily commented@shivam_tiwari Good work!
I think there is one unresolved comment left now? The comment concerning the .module file. I am not sure the suggested code is exactly right. Needs work. And one test is failing. The test describes the failure quite well.
Once these 2 things are done can change to 'Needs review'.
Comment #41
shivam_tiwari commentedI worked on .module file and tested it. Resolved last comment also, updated code is working fine only phpunit test is failing so need to work on this only.
Comment #42
transmitter commentedI believe I've got the same problem on D11 with Drupal Symfony Mailer enabled.
When I try to apply the patch (any of the 3 here, #17 specifically) I get:
Comment #43
isalmanhaider commentedJust experienced on Drupal 11.2.2
with user_registrationpassword 2.0.2
While signing up a new user
Comment #44
mably commented@isalmanhaider you replaced the issue summary with your comment.
Comment #45
isalmanhaider commented@mably pardon for the inconvenience.
Just tried and patch #17 worked for me on Drupal 11.2.2 with PHP 8.3
Comment #46
lakhithad commentedVersion 2.0.3 is released recently, but this bug seems to be still not fixed even in the recent version.
Comment #47
coretex commentedIs the phpunit test green or still failing? What are the last steps before merging?
Comment #48
intrafusionClosing in favour of #3557575: TypeError: _user_registrationpassword_mail_notify(): Return value must be of type array