- Issue created by @pyrello
- π¬π§United Kingdom adamps
You don't have to write an EmailBuilder. This module will call
hook_mail()
if it can be found - seeEmailBuilderManager::findDefinitions()
, this comment:// Add definitions for any implementations of hook_mail() that don't // already have one, using LegacyEmailBuilder.
Maybe something about your test environment causes a problem?
- πΊπΈUnited States pyrello
The test doesn't implement
hook_mail()
. Instead it just calls themail()
method directly. This case doesn't seem to be covered by this module.I could add a
hook_mail()
implementation to our test module. However, that also changes the test. Because it is technically possible to call themai()
method directly, the test would no longer cover that case. - last update
about 1 year ago 5 pass, 2 fail - @pyrello opened merge request.
- πΊπΈUnited States pyrello
@AdamPS, I have added a failing test to demonstrate what I'm talking about.
- π¬π§United Kingdom adamps
I believe the problem is the missing
hook_mail()
rather than that you are callingmail()
directly. I don't currently feel this is an important case for this module to support. You can easily write an emptyhook_mail()
implementation and then calling directly should work. - πΊπΈUnited States pyrello
I would say that the problem is that it is possible to call mail() without an existing implementation and it still works to send mail. Moreover it's been this way for a long time so my guess is that we are not the only ones that used it like this. It seems like this case should be covered even though it's not standard.
Take a look at where the test I added above fails: https://git.drupalcode.org/project/symfony_mailer/-/blob/1.x/src/MailMan...
The
$builder->fromArray()
method is called without a check to ensure that$builder
actually got set to something. At a minimum, there should be a check here that allows it to gracefully fail or trigger an exception. I would contend instead that theEmailBuilderManager::createInstanceFromMessage()
method should return theLegacyEmailBuilder
if no other match is found.I'm happy to add that to my patch, but I was hoping to get some indication of whether this was the correct way to make sure that the
LegacyEmailBuilder
is used if nothing else can be found. - π¬π§United Kingdom adamps
If you want to investigate a fix that's OK, but in my view it's minor so it's not something that's worth changing a lot of code and risking creating new bugs. I think there will be a problem that LegacyEmailBuilder isn't actually a plug-in instance with an ID so you can't create it. Maybe you can find a solution.
- πͺπΈSpain sluc23
I'm facing similar issue but in my case I use AEgir to create Drupal9/10 websites including symfony_mailer as part of the Drupal platform. AEgir installation succeed most of the process but it fails at the very end when it sends a welcome email to notify the site installation.. it tries to send the email as
$mail_success = \Drupal::service('plugin.manager.mail')->mail('install', 'welcome-admin', $mailto, $langcode, $mail_params, $from, TRUE);
ref: https://gitlab.com/aegir/aegir3/provision/-/blob/7.x-3.x/platform/drupal...
and the result is similar as described here:
Error: Call to a member function fromArray() on null in <drupal_root>/web/modules/contrib/symfony_mailer/src/MailManagerReplacement.php on line 89 #0 <provision_root>/platform/drupal/install_9.inc(42): Drupal\symfony_mailer\MailManagerReplacement->mail() #1 /data/disk/lspiegel/.drush/sys/provision/platform/drupal/install_9.inc(187): install_send_welcome_mail() . . .
Definitely this is a different use case as the described as part of the ticket in test suite, but seems to be similar causes.
I'll probably find a workaround to overcome this problem. - π©πͺGermany Anybody Porta Westfalica
Just ran into the same issue: π Implement hook_mail (Error: Call to a member function fromArray() on null in Drupal\symfony_mailer\MailManagerReplacement->mail()) Active
and also found π¬ fromArray() on null in MailManagerReplacement->mail() Closed: works as designedSo I agree it would make sense to fix this or at least make the error message more clear.
- π©πͺGermany Anybody Porta Westfalica
@AdamPS after thinking about this for a while, I think if
EmailBuilderManager::createInstanceFromMessage()
returns NULL that should presumably lead to an error / exception or log entry (or fallback) instead of calling the->fromArray()
method on NULL here:// Create an email from the array. $builder = $this->emailBuilderManager->createInstanceFromMessage($message); $email = $builder->fromArray($this->emailFactory, $message);
What do you think?
BTW in the watchdog_mailer case I don't really understand why that happens, as we have a hook_mail implementation with the correct key, but that's another topic... ;)