/**
  * {@inheritdoc}
  */
 public function createForm($layout = null, $lang = null)
 {
     $edit = $layout !== null;
     $this->locale = $lang ?: $this->defaultLocale;
     if ($edit) {
         $translation = $layout->getTranslation($this->locale);
     } else {
         $layout = new Layout();
         $translation = new LayoutTranslation($this->defaultLocale);
         $translation->setLayout($layout);
     }
     $model = new EntityTranslationModel($layout, $translation);
     return $this->factory->create('mailer_layout', $model, array('data_translation' => $translation, 'edit' => $edit));
 }
示例#2
0
 /**
  * @see Doctrine\Common\DataFixtures.FixtureInterface::load()
  */
 public function load(ObjectManager $manager)
 {
     // layouts
     $translations = array(array('locale' => 'fr', 'body' => 'blablabla {{title}} {% block content %}{% endblock %} blablabla'), array('locale' => 'en', 'body' => 'blublublu {{title}} {% block content %}{% endblock %} blublublu'), array('locale' => 'es', 'body' => 'bliblibli {{title}} {% block content %}{% endblock %} bliblibli'));
     $layout = new Layout();
     $layout->setDescription('super layout');
     $layout->setReference('rabbid-layout');
     foreach ($translations as $trans) {
         $translation = new LayoutTranslation();
         $translation->setBody($trans['body']);
         $translation->setLang($trans['locale']);
         $layout->addTranslation($translation);
     }
     $manager->persist($layout);
     $manager->flush();
     // emails
     $translations = array(array('locale' => 'fr', 'subject' => 'lapin crétins', 'body' => '{{name}} aime les lapins crétins.', 'from_address' => '*****@*****.**', 'from_name' => 'lapin'), array('locale' => 'en', 'subject' => 'raving rabbids', 'body' => '{{name}} likes raving rabbids.', 'from_address' => '*****@*****.**', 'from_name' => 'rabbid'), array('locale' => 'es', 'subject' => 'this template won\'t work', 'body' => '{{name} <-- fail', 'from_address' => '*****@*****.**', 'from_name' => 'rabbid'));
     $email = new Email();
     $email->setBcc('one@email.fr; two@email.fr');
     $email->setDescription('bwah!');
     $email->setReference('rabbids-template');
     $email->setSpool(false);
     $email->setLayout($layout);
     foreach ($translations as $trans) {
         $translation = new EmailTranslation();
         $translation->setLang($trans['locale']);
         $translation->setSubject($trans['subject']);
         $translation->setBody($trans['body']);
         $translation->setFromAddress($trans['from_address']);
         $translation->setFromName($trans['from_name']);
         $email->addTranslation($translation);
     }
     $manager->persist($email);
     $email = new Email();
     $email->setReference('test-headers');
     $email->setSpool(false);
     $email->setHeaders(array(array('key' => 'X-SuperHeader', 'value' => 'TestValue'), array('key' => 'X-MegaHeader', 'value' => 'TestValue'), array('X-Malformed-Header' => 'TestValue'), 'X-Malformed-Header: TestValue'));
     $translation = new EmailTranslation();
     $translation->setLang('fr');
     $translation->setSubject('Email with headers');
     $translation->setBody('Email with headers body');
     $translation->setFromAddress('*****@*****.**');
     $translation->setFromName('Lapins');
     $email->addTranslation($translation);
     $manager->persist($email);
     $manager->flush();
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 public function getLastModifiedTimestamp()
 {
     $date = $this->currentTranslation->getUpdatedAt();
     if (!$date instanceof \DateTime) {
         $date = new \DateTime('now');
     }
     return $date->format('U');
 }
示例#4
0
 /**
  * Get LayoutTranslation for a given lang, if not exist it will be created
  *
  * @param string $lang
  *
  * @throws \InvalidArgumentException
  * @return \Lexik\Bundle\MailerBundle\Entity\LayoutTranslation
  */
 public function getTranslation($lang)
 {
     // Check if locale given
     if (strpos($lang, '_')) {
         $parts = explode('_', $lang);
         $lang = array_shift($parts);
     }
     if (strlen($lang) != 2) {
         throw new \InvalidArgumentException(sprintf('$lang is not valid : "%s" given', $lang));
     }
     foreach ($this->getTranslations() as $translation) {
         if ($translation->getLang() === $lang) {
             return $translation;
         }
     }
     $translation = new LayoutTranslation($lang);
     $translation->setLayout($this);
     return $translation;
 }
示例#5
0
 /**
  * Get LayoutTranslation for a given lang, if not exist it will be created
  *
  * @param string $lang
  *
  * @return \Lexik\Bundle\MailerBundle\Entity\LayoutTranslation
  */
 public function getTranslation($lang)
 {
     // Check if locale given
     if (strpos($lang, '_')) {
         $parts = explode('_', $lang);
         $lang = array_shift($parts);
     }
     foreach ($this->getTranslations() as $translation) {
         if ($translation->getLang() === $lang) {
             return $translation;
         }
     }
     $translation = new LayoutTranslation($lang);
     $translation->setLayout($this);
     return $translation;
 }