/** * Finds and displays a Content entity. * */ public function showAction(Request $request, $id, $maxAge = null, $sharedAge = null, $private = null, $file = false) { // Read if ($file === false) { $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository('JadeITApplicationBundle:Content')->findOneByName($id); } // Check for a static file if (empty($entity)) { $entity = new Content(); $entity->setName($id); $entity->setFormat($request->getRequestFormat()); } if (empty($entity)) { throw $this->createNotFoundException('Unable to find Content entity.'); } // Fire the Read Content Event $event = new ContentEvent($entity, $request); $dispatcher = $this->get('event_dispatcher'); $dispatcher->dispatch('notes.events.content.read', $event); // Render if ($this->get('security.context')->isGranted('ROLE_ADMIN')) { $deleteForm = $this->createDeleteForm($entity->getId())->createView(); } else { $deleteForm = false; } try { $response = $this->container->get('templating')->renderResponse($entity->getTemplate(), array('entity' => $entity, 'delete_form' => $deleteForm)); } catch (\InvalidArgumentException $e) { throw $this->createNotFoundException('Could not find ' . $entity->getName(), $e); } if ($maxAge) { $response->setMaxAge($maxAge); } if ($sharedAge) { $response->setSharedMaxAge($sharedAge); } if ($private) { $response->setPrivate(); } elseif ($private === false || null === $private && ($maxAge || $sharedAge)) { $response->setPublic($private); } return $response; }
public function getContent(ContentEntity $entity, $html = false) { $template = $this->twig->loadTemplate($entity->getTemplate()); return $template->renderBlock($html ? 'content' : 'markdown', array()); }