Problem/Motivation
As describe in #3016953, it would be nice to be able to use hook_mail_alter to make changes to the email based on some values/conditions of the entity. Currently the entity object isn't available in hook_mail_alter though, making this difficult.
Proposed resolution
Pass the entity object to the $this->mailManager as a param so it is available inside hook_mail_alter. This appears to be what the core Contact module does.
Should be possible by changing /src/Plugin/QueueWorker/WorkbenchEmailProcessor.php to add the entity that is already available.
// Send the email.
=$this->mailManager->mail('workbench_email', 'template::' . $template->id(), $data->getTo(), LanguageInterface::LANGCODE_DEFAULT, [
'body' => $body,
'template' => $template,
'subject' => $subject,
'entity' => $entity,
], $replyTo);
Remaining tasks
- Agreement on feature request.
- Make patch to add functionality.
User interface changes
None
API changes
None
Data model changes
None
Issue fork workbench_email-3203414
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
Comment #2
larowlanSounds good
Comment #4
pcate commentedComment #5
larowlanThanks, can we get a test to go with this.
We already have
tests/modules/workbench_email_test/workbench_email_test.moduleso if you put an implementation ofhook_mail_alterin there to add something extra to the titles based of the entity, and then modify\Drupal\Tests\workbench_email\Functional\WorkbenchEmailTestBase::testEndToEndto check that the modification happened we should be coveredThanks!
Comment #6
pcate commentedBy title do you mean adding something to the node title or the email subject?
Comment #7
larowlanSorry, add something extra to the subject based on the entity
Comment #8
pcate commentedComment #9
pcate commentedComment #10
pcate commentedComment #11
pcate commentedTest added.
Comment #13
larowlan🔥hot stuff, merging this and creating a new release.
Great work 👌