/** * Create a new content item. * * @param Request $request * @param integer $type * * @return Response */ public function createAction(Request $request, $type = 0) { /** @var ContentManager $manager */ $manager = $this->get('opifer.content.content_manager'); if ($type) { $contentType = $this->get('opifer.content.content_type_manager')->getRepository()->find($type); $content = $this->get('opifer.eav.eav_manager')->initializeEntity($contentType->getSchema()); $content->setContentType($contentType); } else { $content = $manager->initialize(); } $form = $this->createForm(ContentType::class, $content); $form->handleRequest($request); if ($form->isValid()) { // Create a new document $blockManager = $this->get('opifer.content.block_manager'); $document = new DocumentBlock(); $document->setPublish(true); $document->setSuper($content->getTemplate()->getBlock()); $blockManager->save($document); $content->setBlock($document); $manager->save($content); return $this->redirectToRoute('opifer_content_contenteditor_design', ['type' => 'content', 'id' => $content->getId(), 'rootVersion' => 0]); } return $this->render($this->getParameter('opifer_content.content_new_view'), ['form' => $form->createView()]); }
/** * Graphical Content editor * * @param Request $request * @param integer $id * @param integer $version * * @return Response */ public function editAction(Request $request, $id, $version = 1) { $this->getDoctrine()->getManager()->getFilters()->disable('draftversion'); /** @var ContentManager $contentManager */ $contentManager = $this->get('opifer.content.content_manager'); /** @var BlockManager $blockManager */ $blockManager = $this->get('opifer.content.block_manager'); $content = $contentManager->getRepository()->find($id); if (!$content) { throw $this->createNotFoundException('No content found for id ' . $id); } if (!$content->getBlock()) { // Create a new document $version = 1; $document = new DocumentBlock(); $document->setRootVersion(1); $content->setBlock($document); $contentManager->save($content); } if (!$version) { $version = $blockManager->getNewVersion($content->getBlock()); $content->getBlock()->setRootVersion($version); } $parameters = ['manager' => $blockManager, 'block' => $content->getBlock(), 'id' => $content->getId(), 'title' => $content->getTitle(), 'permalink' => $this->generateUrl('_content', ['slug' => $content->getSlug()]), 'version_current' => $version, 'version_published' => $content->getBlock()->getVersion(), 'url_properties' => $this->generateUrl('opifer_content_content_details', ['id' => $content->getId()]), 'url_cancel' => $this->generateUrl('opifer_content_content_index', []), 'url' => $this->generateUrl('opifer_content_contenteditor_view', ['id' => $content->getBlock()->getId(), 'version' => $version])]; return $this->render('OpiferContentBundle:Editor:view.html.twig', $parameters); }
/** * Graphical Content editor * * @param Request $request * @param string $type * @param integer $version * * @return Response */ public function designAction(Request $request, $type, $id, $version = 0) { $this->getDoctrine()->getManager()->getFilters()->disable('draftversion'); /** @var BlockManager $blockManager */ $blockManager = $this->get('opifer.content.block_manager'); /** @var AbstractDesignSuite $suite */ $suite = $this->get(sprintf('opifer.content.%s_design_suite', $type)); $suite->load($id, $version); if (!$suite->getBlock()) { // Create a new document $version = 1; $document = new DocumentBlock(); $document->setRootVersion(1); $suite->setBlock($document); $suite->saveSubject(); } if (!$version) { $version = $blockManager->getNewVersion($suite->getBlock()); $suite->getSubject()->getBlock()->setRootVersion($version); } $parameters = ['manager' => $blockManager, 'block' => $suite->getBlock(), 'id' => $suite->getSubject()->getId(), 'type' => $type, 'title' => $suite->getTitle(), 'caption' => $suite->getCaption(), 'permalink' => $suite->getPermalink(), 'version_current' => $version, 'version_published' => $suite->getBlock()->getVersion(), 'url_properties' => $suite->getPropertiesUrl(), 'url_cancel' => $suite->getCancelUrl(), 'url' => $suite->getCanvasUrl($version)]; return $this->render($this->getParameter('opifer_content.content_edit_view'), $parameters); }