class MandrillTemplateService in Mandrill 8
Mandrill Template service.
Overrides Mandrill Service to allow sending of templated messages.
Hierarchy
- class \Drupal\mandrill\MandrillService implements MandrillServiceInterface
- class \Drupal\mandrill_template\MandrillTemplateService
Expanded class hierarchy of MandrillTemplateService
1 string reference to 'MandrillTemplateService'
- mandrill_template.services.yml in modules/
mandrill_template/ mandrill_template.services.yml - modules/mandrill_template/mandrill_template.services.yml
1 service uses MandrillTemplateService
- mandrill.service in modules/
mandrill_template/ mandrill_template.services.yml - Drupal\mandrill_template\MandrillTemplateService
File
- modules/
mandrill_template/ src/ MandrillTemplateService.php, line 17 - Contains \Drupal\mandrill_template\MandrillTemplateService.
Namespace
Drupal\mandrill_templateView source
class MandrillTemplateService extends MandrillService {
/**
* {@inheritdoc}
*/
public function send($message) {
$template_map = null;
if (isset($message['id']) && isset($message['module'])) {
// Check for a template map to use with this message.
$template_map = mandrill_template_map_load_by_mailsystem($message['id'], $message['module']);
}
try {
if (!empty($template_map)) {
// Send the message with template information.
$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 {
// No template map, so send a standard message.
$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;
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MandrillService:: |
protected | property | The Config Factory service. | |
MandrillService:: |
protected | property | The Logger Factory service. | |
MandrillService:: |
protected | property | The Mandrill API service. | |
MandrillService:: |
public | function |
Get the mail systems defined in the mail system module. Overrides MandrillServiceInterface:: |
|
MandrillService:: |
public | function |
Helper to generate an array of recipients. Overrides MandrillServiceInterface:: |
|
MandrillService:: |
protected | function | Response handler for sent messages. | 1 |
MandrillService:: |
public | function | Constructs the service. | |
MandrillTemplateService:: |
public | function |
Abstracts sending of messages, allowing queueing option. Overrides MandrillService:: |