Implemented view for node

This commit is contained in:
Kevin Frantz
2018-09-20 16:03:00 +02:00
parent 1915c77d8c
commit ee1cef71b7
7 changed files with 117 additions and 1 deletions

View File

@@ -0,0 +1,43 @@
<?php
namespace App\Controller;
use FOS\RestBundle\Controller\FOSRestController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Entity\NodeInterface;
use App\Entity\Node;
/**
* @todo IMPLEMENT SECURITY!
*
* @author kevinfrantz
*/
class NodeController extends FOSRestController
{
/**
* @Route("/node/{id}.{_format}", defaults={"_format"="html"})
*/
public function show(Request $request, int $id): Response
{
$node = $this->loadSource($request, $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
{
$node = $this->getDoctrine()
->getRepository(Node::class)
->find($id);
if (!$node) {
throw $this->createNotFoundException('No node found for id '.$id);
}
return $node;
}
}

View File

@@ -11,6 +11,7 @@ use FOS\RestBundle\Controller\FOSRestController;
use App\Entity\SourceInterface;
use App\Creator\Factory\Template\Source\SourceTemplateFormFactory;
use App\Creator\Factory\Form\Source\SourceFormFactory;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
* @todo IMPLEMENT SECURITY!
@@ -50,6 +51,16 @@ class SourceController extends FOSRestController
]);
}
/**
* @Route("/source/{id}/node.{_format}", defaults={"_format"="html"})
*/
public function node(Request $request, int $id): RedirectResponse
{
$source = $this->loadSource($request, $id);
return $this->redirectToRoute('app_node_show', ['id' => $source->getNode()->getId()]);
}
private function loadSource(Request $request, int $id): SourceInterface
{
$source = $this->getDoctrine()

View File

@@ -12,7 +12,7 @@ use App\Entity\Attribut\LawAttribut;
/**
* @author kevinfrantz
* @ORM\Table(name="node")
* @ORM\Entity(repositoryClass="App\Repository\NodeRepository")
* @ORM\Entity()
*/
class Node extends AbstractEntity implements NodeInterface
{

View File

@@ -39,6 +39,15 @@ class SourceMenuSubscriber implements EventSubscriberInterface
],
]);
$this->generateSourceFormatDropdown($menu, $event);
$menu->addChild($this->translator->trans('node'), [
'route' => 'app_source_node',
'routeParameters' => [
'id' => $event->getRequest()->getCurrentRequest()->attributes->get('id'),
],
'attributes' => [
'icon' => 'fas fa-globe',
],
]);
}
private function generateSourceFormatDropdown(ItemInterface $menu, SourceMenuEvent $event): void