/** * @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); }
/** * Add block * * @param WebDev\ContentBundle\Entity\Block $block */ public function addBlock(Block $block) { if (!$block->getPlaceholder()) { throw new Exception("Cannot add content block without a placeholder."); } $this->blocks[$block->getPlaceholder()] = $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); }
/** * Adds a block to this context * * @param WebDev\ContentBundle\Entity\Block $block */ public function addBlock(Block $block) { $this->blocks[$block->getPlaceholder()] = $block; }
public function getBlockAdminUri(Block $block, $format = 'html') { $router = $this->router; $page = $block->getPage(); return $router->generate('webdev_content_admin_block', array('route' => $page->getRoute(), 'placeholder' => $block->getPlaceholder(), '_format' => $format)); }