Commit 54dd0367 authored by dpi's avatar dpi

Email channel will now use reply-to passed to options parameter

Added options parameter to IdentityChannelManager::sendMessage()
Changed method ChannelInterface parameter type hinting
parent 6834d370
......@@ -22,7 +22,7 @@ interface ChannelInterface extends EntityInterface {
* @param array $tokens
* An array of tokens keyed by token type.
*/
public function applyTokens($tokens);
public function applyTokens(array $tokens);
/**
* Gets token values added to this channel.
......@@ -51,6 +51,6 @@ interface ChannelInterface extends EntityInterface {
* @param array $options
* Miscellaneous options to pass to the sender.
*/
public function sendMessage($options = []);
public function sendMessage(array $options = []);
}
......@@ -111,7 +111,7 @@ class Email extends ContentEntityBase implements EmailInterface {
/**
* {@inheritdoc}
*/
public function applyTokens($tokens) {
public function applyTokens(array $tokens) {
foreach ($tokens as $token => $value) {
$this->tokens[$token] = $value;
}
......@@ -131,6 +131,10 @@ class Email extends ContentEntityBase implements EmailInterface {
/**
* {@inheritdoc}
*
* @param array $options
* Miscellaneous options.
* - reply_to: reply-to email address, or leave unset to use site default.
*/
static public function sendMessages(array $messages, $options = []) {
/* @var \Drupal\courier\EmailInterface[] $messages */
......@@ -151,13 +155,15 @@ class Email extends ContentEntityBase implements EmailInterface {
],
];
\Drupal::service('plugin.manager.mail')->mail(
/** @var \Drupal\Core\Mail\MailManagerInterface $mailman */
$mailman = \Drupal::service('plugin.manager.mail');
$mailman->mail(
'system',
'courier_email',
$email_to,
$message->language()->getId(),
$params,
NULL
array_key_exists('reply_to', $options) ? $options['reply_to'] : NULL
);
}
}
......@@ -165,7 +171,7 @@ class Email extends ContentEntityBase implements EmailInterface {
/**
* {@inheritdoc}
*/
public function sendMessage($options = []) {
public function sendMessage(array $options = []) {
$this->sendMessages([$this], $options);
}
......
......@@ -119,8 +119,10 @@ class IdentityChannelManager extends DefaultPluginManager implements IdentityCha
/**
* {@inheritdoc}
*/
public function sendMessage(TemplateCollectionInterface $template_collection, EntityInterface $identity) {
public function sendMessage(TemplateCollectionInterface $template_collection, EntityInterface $identity, array $options = []) {
$template_collection->validateTokenValues();
$channel_options = isset($options['channels']) ? $options['channels'] : [];
unset($options['channels']);
foreach ($this->getChannelsForIdentity($identity) as $channel) {
if ($template = $template_collection->getTemplate($channel)) {
if ($plugin = $this->getCourierIdentity($channel, $identity->getEntityTypeId())) {
......@@ -130,7 +132,13 @@ class IdentityChannelManager extends DefaultPluginManager implements IdentityCha
'identity' => $identity,
]);
$plugin->applyIdentity($template, $identity);
$template->sendMessage();
// Transform options based on channel
$options_new = $options;
if (array_key_exists($channel, $channel_options)) {
$options_new = array_merge($options, $channel_options[$channel]);
}
$template->sendMessage($options_new);
}
}
}
......
......@@ -85,7 +85,27 @@ interface IdentityChannelManagerInterface {
* A channel entity.
* @param \Drupal\Core\Entity\EntityInterface $identity
* An identity entity.
* @param array $options
* Optional options to pass to the channel.
* If the 'channels' key is specified, this will find a sub array with the
* key of the channel being transmitted to, and merge it into the base
* base array. The channels key will then be unset.
* e.g: Sending to the courier_email channel:
* @code
* $options = [
* 'my_option' => 123,
* 'channels' => [
* 'courier_email' => ['foo' => 456],
* 'sms' => ['bar' => 679],
* ],
* ];
* // Will transform options into this array when sending to courier_email:
* $options = [
* 'my_option' => 123,
* 'foo' => 456,
* ];
* @endcode
*/
public function sendMessage(TemplateCollectionInterface $template_collection, EntityInterface $identity);
public function sendMessage(TemplateCollectionInterface $template_collection, EntityInterface $identity, array $options = []);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment