/**
  * Test clone, toString
  */
 public function testCloneAndToString()
 {
     $translation = $this->getMock('Oro\\Bundle\\EmailBundle\\Entity\\EmailTemplateTranslation');
     $this->emailTemplate->getTranslations()->add($translation);
     $clone = clone $this->emailTemplate;
     $this->assertNull($clone->getId());
     $this->assertEquals($clone->getParent(), $this->emailTemplate->getId());
     $this->assertFalse($clone->getIsSystem());
     $this->assertTrue($clone->getIsEditable());
     $this->assertEquals($this->emailTemplate->getName(), (string) $this->emailTemplate);
     $this->assertFalse($clone->getTranslations()->first() === $translation);
 }
Пример #2
0
 /**
  * Process form
  *
  * @param  EmailTemplate $entity
  *
  * @return bool True on successful processing, false otherwise
  */
 public function process(EmailTemplate $entity)
 {
     // always use default locale during template edit in order to allow update of default locale
     $entity->setLocale($this->defaultLocale);
     if ($entity->getId()) {
         // refresh translations
         $this->manager->refresh($entity);
     }
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         // deny to modify system templates
         if ($entity->getIsSystem() && !$entity->getIsEditable()) {
             $this->form->addError(new FormError($this->translator->trans('oro.email.handler.attempt_save_system_template')));
             return false;
         }
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             // mark an email template creating by an user as editable
             if (!$entity->getId()) {
                 $entity->setIsEditable(true);
             }
             $this->manager->persist($entity);
             $this->manager->flush();
             return true;
         }
     }
     return false;
 }
 /**
  * @param EmailTemplate $template
  *
  * @return Closure
  */
 protected function createExistingEntityQueryBuilder(EmailTemplate $template)
 {
     return function (EmailTemplateRepository $repository) use($template) {
         $qb = $repository->createQueryBuilder('e');
         return $qb->orderBy('e.name', 'ASC')->andWhere('e.entityName = :entityName OR e.entityName IS NULL')->andWhere("e.organization = :organization")->andWhere($qb->expr()->orX($qb->expr()->eq('e.visible', ':visible'), $qb->expr()->eq('e.id', ':id')))->setParameter('entityName', Email::ENTITY_CLASS)->setParameter('organization', $this->securityFacade->getOrganization())->setParameter('id', $template->getId())->setParameter('visible', true);
     };
 }