Skip to content
Snippets Groups Projects
Commit fa7021d4 authored by Adam Shepherd's avatar Adam Shepherd
Browse files

Issue #3263447 by AdamPS: Extend hook_mailer_bc_alter() to allow altering 'to' and 'reply-to'

parent 7822ef6b
Branches
Tags
No related merge requests found
......@@ -54,7 +54,7 @@ class MailManagerReplacement extends MailManager {
*/
public function mail($module, $key, $to, $langcode, $params = [], $reply = NULL, $send = TRUE) {
// Call alter hook.
$context = ['module' => $module, 'entity' => NULL];
$context = ['module' => $module, 'to' => $to, 'reply' => $reply, 'entity' => NULL];
$this->moduleHandler->alter(['mailer_bc', "mailer_bc_$module"], $key, $params, $context);
if ($entity = $context['entity']) {
......@@ -64,10 +64,10 @@ class MailManagerReplacement extends MailManager {
$email = $this->emailFactory->newModuleEmail($module, $key);
}
$email->setTo($to)
$email->setTo($context['to'])
->setLangcode($langcode)
->setParams($params);
if ($reply) {
if ($context['reply']) {
$email->setReplyTo($reply);
}
......
......@@ -16,8 +16,10 @@
* @param array $params
* The email parameters.
* @param array $context
* Array with two entries
* Array with entries:
* - module: The email type, known as 'module' on the old interface.
* - to: The email 'to' address.
* - reply: The email 'reply-to' address.
* - entity: The associated config entity, always null on the old interface.
*
* @see \Drupal\Core\Mail\MailManagerInterface::mail()
......@@ -34,8 +36,10 @@ function hook_mailer_bc_alter(string &$key, array &$params, array &$context) {
* @param array $params
* The email parameters.
* @param array $context
* Array with two entries
* Array with entries:
* - module: The email type, known as 'module' on the old interface.
* - to: The email 'to' address.
* - reply: The email 'reply-to' address.
* - entity: The associated config entity, always null on the old interface.
*/
function hook_mailer_bc_MODULE_alter(string &$key, array &$params, array &$context) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment