Problem/Motivation

Invite by Email is using the Mail API but does not implement hook_mail(). This means other modules are not fully able to use hook_mail_alter() on Invite by Email messages. In particular, the subject and body are added after hook_mail_alter() is run. It's also possible inconsistent states could be introduced when other modules introduce changes the could be partially overwritten.

See #2975515-4: invite email is not being sent for an explanation of how the email code current works.

Proposed resolution

Implement hook_mail().

Comments

dale42 created an issue. See original summary.

dale42’s picture

Issue summary: View changes
dale42’s picture

StatusFileSize
new7.5 KB

The following patch implements hook_mail() in the Invite by Email module.

I used the User module user_mail() and Examples module implementations as guides.

I tested the patch with native Drupal mail, Swift Mailer, and the Swift Mailer replacement, Symfony Mailer.

socialnicheguru’s picture

Status: Active » Needs review
avpaderno’s picture

Title: hook_mail() not fully implemented » Implement hook_mail()
Category: Bug report » Task
dale42’s picture

StatusFileSize
new7.5 KB

Small update to the patch. I used a trailing comma in the parameter lists of the class constructor and the return value of the create method. That's a PHP 8.0 feature. I've removed it so the code works in PHP 7.

avpaderno’s picture

+      $this->messenger->addStatus($this->t('Invitation has been sent.'));
+      \Drupal::logger('invite')->notice(
+        'Invitation has been sent for: @mail_user.', ['@mail_user' => $to]

Since the plugin constructor parameters are changed, the logger could also be injected.

renatog’s picture

Since the plugin constructor parameters are changed, the logger could also be injected.

Ah yeah, good catch! Makes sense

renatog’s picture

Status: Needs review » Reviewed & tested by the community

I applied and tested the patch and really works fine. Moving to RTBC

Regarding the @apaderno 's comment at #7, it really makes sense. I think we can implement that in a separated ticket to fix all dependency injection #3276084: Fix all dependency injection in the Invite

  • RenatoG committed 152597f on 8.x-1.x authored by dale42
    Issue #3275572 by dale42, apaderno, SocialNicheGuru, RenatoG: Implement...
renatog’s picture

Status: Reviewed & tested by the community » Fixed

Committed to the dev branch 8.x-1.x

Thank a lot everyone and @dale42 for your great job! Keep pushing dude o/

renatog’s picture

Just to let you know, I was talking to @dale42 and we're organizing to create the new release to get the fixes that was included in the dev branch

Status: Fixed » Closed (fixed)

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