/** * Setter for Template * * @param Newscoop\Entity\Snippet\SnippetTemplate $template * * @return Newscoop\Entity\Snippet */ public function setTemplate(SnippetTemplate $template) { $this->template = $template; foreach ($template->getFields() as $templateField) { $field = new SnippetField($templateField); $field->setSnippet($this); $this->addField($field); } $this->setModified(); return $this; }
public function save(SnippetTemplate $snippetTemplate) { if (!$snippetTemplate->hasName()) { throw new \InvalidArgumentException("SnippetTemplate name cannot be empty"); } if (!$snippetTemplate->hasTemplateCode()) { throw new \InvalidArgumentException("SnippetTemplate templateCode cannot be empty"); } if (!$snippetTemplate->hasFields()) { throw new \InvalidArgumentException("SnippetTemplate requires at least 1 SnippetTemplateField"); } foreach ($snippetTemplate->getFields()->toArray() as $field) { $field->setTemplate($snippetTemplate); } $em = $this->getEntityManager(); $em->persist($snippetTemplate); $em->flush(); }