You are here

class MandrillTemplateService in Mandrill 8

Mandrill Template service.

Overrides Mandrill Service to allow sending of templated messages.

Hierarchy

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_template
View 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

Namesort descending Modifiers Type Description Overrides
MandrillService::$config protected property The Config Factory service.
MandrillService::$log protected property The Logger Factory service.
MandrillService::$mandrill_api protected property The Mandrill API service.
MandrillService::getMailSystems public function Get the mail systems defined in the mail system module. Overrides MandrillServiceInterface::getMailSystems
MandrillService::getReceivers public function Helper to generate an array of recipients. Overrides MandrillServiceInterface::getReceivers
MandrillService::handleSendResponse protected function Response handler for sent messages. 1
MandrillService::__construct public function Constructs the service.
MandrillTemplateService::send public function Abstracts sending of messages, allowing queueing option. Overrides MandrillService::send