/** * Find the translation and translate the template if translation is found. * * @param LayoutInterface|MailInterface $template The template * @param string $locale The locale * * @return bool */ public static function find($template, $locale) { $locale = strtolower($locale); foreach ($template->getTranslations() as $translation) { if ($locale === strtolower($translation->getLocale())) { static::injectValue($template, $translation, 'label'); static::injectValue($template, $translation, 'description'); static::injectValue($template, $translation, 'body'); static::injectFile($template, $translation); if ($template instanceof MailInterface) { static::injectValue($template, $translation, 'subject'); static::injectValue($template, $translation, 'htmlBody'); } return true; } } return false; }
/** * Add the mail template. * * @param MailInterface $mail The mail template */ public function addMail(MailInterface $mail) { $this->mails[$mail->getName()] = $mail; }
/** * Render the template. * * @param string $template The template string * @param LayoutInterface|MailInterface $templateInstance The template instance * @param array $variables The variables of template * * @return string The rendered template * * @throws \Exception */ protected function renderTemplate($template, $templateInstance, array $variables = array()) { if (null !== $template) { if ($templateInstance instanceof TwigTemplateInterface) { $tpl = $this->renderer->loadTemplate($templateInstance->getFile()); if ($tpl instanceof \Twig_Template) { $template = $tpl->renderBlock($template, $variables); $template = '' === $template ? null : $template; } } else { $tpl = $this->renderer->createTemplate($template); $template = $tpl->render($variables); } } return $template; }
/** * 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); }