Exemplo n.º 1
0
 /**
  * Render the mail.
  *
  * @param FilterPreRenderEvent $preEvent The template pre event
  * @param MailInterface        $mail     The mail
  *
  * @return MailRendered
  */
 protected function doRender(FilterPreRenderEvent $preEvent, MailInterface $mail)
 {
     $variables = $preEvent->getVariables();
     $variables['_mail_type'] = $mail->getType();
     $variables['_layout'] = null !== $mail->getLayout() ? $mail->getLayout()->getName() : null;
     $subject = $this->renderTemplate($mail->getSubject(), $mail, $variables);
     $variables['_subject'] = $subject;
     $htmlBody = $this->renderTemplate($mail->getHtmlBody(), $mail, $variables);
     $variables['_html_body'] = $htmlBody;
     $body = $this->renderTemplate($mail->getBody(), $mail, $variables);
     $variables['_body'] = $body;
     $layout = $this->getTranslatedLayout($mail);
     if (null !== $layout && null !== ($lBody = $layout->getBody()) && !MailUtil::isRootBody($htmlBody)) {
         $htmlBody = $this->renderTemplate($lBody, $layout, $variables);
     }
     return new MailRendered($mail, $subject, $htmlBody, $body);
 }
Exemplo n.º 2
0
 /**
  * Check if the mail template is valid.
  *
  * @param MailInterface $mail The mail template
  * @param string        $type The mail type defined in MailTypes::TYPE_*
  *
  * @return bool
  */
 public static function isValid(MailInterface $mail, $type)
 {
     $validTypes = static::getValidTypes($type);
     return $mail->isEnabled() && in_array($mail->getType(), $validTypes);
 }