mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 21:57:16 +02:00
Added AbstractEntityController
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user