Added AbstractEntityController

This commit is contained in:
Kevin Frantz
2018-10-03 18:55:33 +02:00
parent 94bc8c5da4
commit af860429b9
7 changed files with 77 additions and 35 deletions

View File

@@ -2,7 +2,6 @@
namespace App\Controller;
use FOS\RestBundle\Controller\FOSRestController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
@@ -14,29 +13,25 @@ use App\Entity\Node;
*
* @author kevinfrantz
*/
class NodeController extends FOSRestController
class NodeController extends AbstractEntityController
{
/**
* @Route("/node/{id}.{_format}", defaults={"_format"="html"})
*/
public function show(Request $request, int $id): Response
{
$node = $this->loadSource($request, $id);
/**
* @var NodeInterface $node
*/
$node = $this->loadEntityById($id);
$view = $this->view($node, 200)
->setTemplate('node/view/standard.html.twig')
->setTemplateVar('node');
return $this->handleView($view);
}
private function loadSource(Request $request, int $id): NodeInterface
protected function setEntityName(): void
{
$node = $this->getDoctrine()
->getRepository(Node::class)
->find($id);
if (!$node) {
throw $this->createNotFoundException('No node found for id '.$id);
}
return $node;
$this->entityName = Node::class;
}
}