/** * @Route("/admin/content/{route}/{placeholder}") * @Template */ public function blockAction($route, $placeholder) { $request = $this->get('request'); $em = $this->get('doctrine.orm.entity_manager'); $pageRepository = $this->get('content.page_repository'); $blockRepository = $this->get('content.block_repository'); $page = $pageRepository->findOneByRoute($route); if (is_null($page)) { $page = new Page(); $page->setRoute($route); } if ($page->getBlocks()->containsKey($placeholder)) { $block = $page->getBlocks()->get($placeholder); } else { $block = new Block(); $block->setPage($page); $block->setPlaceholder($placeholder); } // Process the form if ($request->getMethod() == "POST") { if ($request->request->get('content')) { $block->setContent($request->request->get('content')); $em->persist($block); $em->flush(); } } return array('page' => $page, 'block' => $block); }
public function add($placeholder, $content) { $context = $this->contentManager->getContext(); $page = $context->getPage(); $block = new Block(); $block->setPage($page); $block->setPlaceholder($placeholder); $block->setContent($content); $page->addBlock($block); }