MandrillTemplateService.php in Mandrill 8
File
modules/mandrill_template/src/MandrillTemplateService.php
View source
<?php
namespace Drupal\mandrill_template;
use Drupal\mandrill\MandrillService;
class MandrillTemplateService extends MandrillService {
public function send($message) {
$template_map = null;
if (isset($message['id']) && isset($message['module'])) {
$template_map = mandrill_template_map_load_by_mailsystem($message['id'], $message['module']);
}
try {
if (!empty($template_map)) {
$template_content = array(
array(
'name' => $template_map->main_section,
'content' => $message['html'],
),
);
if (isset($message['mandrill_template_content'])) {
$template_content = array_merge($message['mandrill_template_content'], $template_content);
}
$response = $this->mandrill_api
->sendTemplate($message, $template_map->template_id, $template_content);
}
else {
$response = $this->mandrill_api
->send($message);
}
} catch (\Exception $e) {
$this->log
->error('Error sending email from %from to %to. @code: @message', array(
'%from' => $message['from_email'],
'%to' => $message['to'],
'@code' => $e
->getCode(),
'@message' => $e
->getMessage(),
));
return FALSE;
}
if (!empty($response)) {
return $this
->handleSendResponse($response, $message);
}
else {
return FALSE;
}
}
}