/**
  * @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);
 }
 /**
  * Injects the relevant content for the context into each request
  * 
  * @param Symfony\Component\HttpKernel\Event\GetResponseEvent $event
  */
 public function onRequestLoadContext(GetResponseEvent $event)
 {
     if (!$this->context) {
         // Create the content context
         $this->context = new ContentContext();
         // Retrieve all the 'unbound' blocks as a basis for the context
         $this->context->addBlocks($this->blockRepository->findUnbound());
         // Layer the page ontop of the context (if available)
         $route = $event->getRequest()->attributes->get('_route');
         if (!$route) {
             $this->log->err("Route is not yet assigned, cannot load page context.");
             return;
         }
         if ($page = $this->pageRepository->findOneByRoute($route)) {
             $this->context->setPage($page);
         } else {
             $this->log->info("No content page found matching route `{$route}`");
             $page = new Page();
             $page->setRoute($route);
             $this->context->setPage($page);
         }
     }
     // Store the context in the request and template engine
     $event->getRequest()->attributes->set('content', $this->context);
 }