/** * @param EmailInterface $email * @param string $locale */ public function getTemplatesPreview(EmailInterface $email, $locale) { $email->setLocale($locale); $this->renderer->loadTemplates($email); $this->renderer->setStrictVariables(false); $this->templates['fromName'] = $email->getFromName($this->defaultEmail); $this->templates['subject'] = $email->getSubject(); $this->templates['content'] = $email->getBody(); $this->errors = array('subject' => null, 'from_name' => null, 'html_content' => null); $suffix = $email->getChecksum(); foreach ($this->errors as $template => $error) { try { $this->renderer->renderTemplate(sprintf('%s_%s', $template, $suffix)); } catch (\Twig_Error $e) { $this->errors[$template] = $e->getRawMessage(); } } $this->renderer->setStrictVariables(true); }
/** * Load all templates for the given email (also load the related layout). * * @param EmailInterface $email */ public function setEmailTemplates(EmailInterface $email) { if ($email->getLayout()) { // call of getLayoutBody set locale on layout $body = $email->getLayoutBody(); // now we can compute correctly the key cache $layoutSuffix = $email->getLayout()->getChecksum(); $this->setTemplate(sprintf('layout_%s', $layoutSuffix), $body); $this->updateDates[sprintf('layout_%s', $layoutSuffix)] = $email->getLayout()->getLastModifiedTimestamp(); $content = strtr('{% extends \'<layout>\' %}{% block content %}<content>{% endblock %}', array('<layout>' => sprintf('layout_%s', $layoutSuffix), '<content>' => $email->getBody())); } else { $content = $email->getBody(); } $emailSuffix = $email->getChecksum(); $this->setTemplate(sprintf('html_content_%s', $emailSuffix), $content); $this->setTemplate(sprintf('text_content_%s', $emailSuffix), $email->getBodyText()); $this->setTemplate(sprintf('subject_%s', $emailSuffix), $email->getSubject()); $this->setTemplate(sprintf('from_name_%s', $emailSuffix), $email->getFromName()); $this->setTemplate(sprintf('from_address_%s', $emailSuffix), $email->getFromAddress()); // keep updated at to be able to check if the template is fresh $this->updateDates[sprintf('html_content_%s', $emailSuffix)] = $email->getLastModifiedTimestamp(); $this->updateDates[sprintf('text_content_%s', $emailSuffix)] = $email->getLastModifiedTimestamp(); $this->updateDates[sprintf('subject_%s', $emailSuffix)] = $email->getLastModifiedTimestamp(); $this->updateDates[sprintf('from_name_%s', $emailSuffix)] = $email->getLastModifiedTimestamp(); $this->updateDates[sprintf('from_address_%s', $emailSuffix)] = $email->getLastModifiedTimestamp(); }
/** * Render email from address * * @param EmailInterface $email * @param array $parameters * * @return string */ protected function renderFromAddress(EmailInterface $email, array $parameters = array()) { if (null === $email->getFromAddress()) { return $this->options['admin_email']; } return $this->renderTemplate('from_address', $parameters, $email->getChecksum()); }