/** * @Route("/update/{id}", name="spliced_cms_admin_layout_update") * @Template("SplicedCmsBundle:Admin/Layout:edit.html.twig") */ public function updateAction($id) { $layout = $this->getDoctrine()->getRepository('SplicedCmsBundle:Layout')->findOneById($id); if (!$layout) { return $this->createNotFoundException('Layout Not Found'); } if (!$layout->getTemplate() || !$layout->getTemplate()->getVersion()) { throw new \RuntimeException(sprintf('Expected a Template and a Template Version')); } $originalContent = $layout->getTemplate()->getVersion()->getContent(); $form = $this->createLayoutForm($layout); if ($form->submit($this->get('request')) && $form->isValid()) { $layout = $form->getData(); $userLabel = trim($form['template']['label']->getData()); if (md5($originalContent) != md5(trim($layout->getTemplate()->getVersion()->getContent()))) { // save new version $templateVersion = new TemplateVersion(); $templateVersion->setTemplate($layout->getTemplate())->setLabel($userLabel ? $userLabel : date('m/d/Y h:i:a'))->setContent(trim($layout->getTemplate()->getVersion()->getContent())); $layout->getTemplate()->setVersion($templateVersion); } else { if ($userLabel) { $layout->getTemplate()->getVersion()->setLabel($userLabel); } } try { $this->get('spliced_cms.layout_manager')->update($layout); $this->get('session')->getFlashBag()->add('success', 'Layout Successfully Updated'); return $this->redirect($this->generateUrl('spliced_cms_admin_layout_edit', array('id' => $layout->getId()))); } catch (\Exception $e) { if ($this->get('kernel')->getEnvironment() == 'dev') { throw $e; } $this->get('session')->getFlashBag()->add('error', 'Error Updating Layout'); return array('layout' => $layout, 'form' => $form->createView()); } } else { $this->get('session')->getFlashBag()->add('error', 'You submission contains invalid data'); } return array('layout' => $layout, 'form' => $form->createView()); }
/** * @Route("/update/{id}", name="spliced_cms_admin_content_block_update") * @Template("SplicedCmsBundle:Admin/ContentBlock:edit.html.twig") */ public function updateAction($id) { $contentBlock = $this->getDoctrine()->getRepository('SplicedCmsBundle:ContentBlock')->findOneById($id); if (!$contentBlock) { return $this->createNotFoundException('Content Block Not Found'); } $originalContent = $contentBlock->getTemplate()->getVersion()->getContent(); $form = $this->createContentBlockForm($contentBlock); if ($form->submit($this->get('request')) && $form->isValid()) { $contentBlock = $form->getData(); $userLabel = trim($form['template']['label']->getData()); if (md5($originalContent) != md5(trim($contentBlock->getTemplate()->getVersion()->getContent()))) { // save new version $templateVersion = new TemplateVersion(); $templateVersion->setTemplate($contentBlock->getTemplate())->setLabel($userLabel ? $userLabel : date('m/d/Y h:i:a'))->setContent(trim($contentBlock->getTemplate()->getVersion()->getContent())); } else { if ($userLabel) { $contentBlock->getTemplate()->getVersion()->setLabel($userLabel); } } try { $this->get('spliced_cms.content_block_manager')->update($contentBlock); $this->get('session')->getFlashBag()->add('success', 'Content Block Successfully Updated'); return $this->redirect($this->generateUrl('spliced_cms_admin_content_block_edit', array('id' => $contentBlock->getId()))); } catch (\Exception $e) { if ($this->get('kernel')->getEnvironment() == 'dev') { throw $e; } $this->get('session')->getFlashBag()->add('error', 'Error Updating Content Block'); return array('contentBlock' => $contentBlock, 'form' => $form->createView()); } } else { $this->get('session')->getFlashBag()->add('error', 'You submission contains invalid data.'); } return array('contentBlock' => $contentBlock, 'form' => $form->createView()); }