2021-03-20 13:40:38 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Core\Controller\Site;
|
|
|
|
|
|
|
|
use App\Core\Controller\Admin\AdminController;
|
|
|
|
use App\Core\Entity\Site\Navigation;
|
|
|
|
use App\Core\Factory\Site\MenuFactory;
|
|
|
|
use App\Core\Form\Site\MenuType;
|
|
|
|
use App\Core\Repository\Site\NavigationRepositoryQuery;
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Route("/admin/site/tree")
|
|
|
|
*/
|
|
|
|
class TreeAdminController extends AdminController
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @Route("/", name="admin_site_tree_index")
|
|
|
|
*/
|
|
|
|
public function index(NavigationRepositoryQuery $navigationQuery): Response
|
|
|
|
{
|
|
|
|
$navigation = $navigationQuery->create()->findOne();
|
|
|
|
|
|
|
|
if (null === $navigation) {
|
2021-03-24 17:09:13 +01:00
|
|
|
$this->addFlash('warning', 'You must add a navigation.');
|
2021-03-20 13:40:38 +01:00
|
|
|
|
|
|
|
return $this->redirectToRoute('admin_site_navigation_new');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->redirectToRoute('admin_site_tree_navigation', [
|
|
|
|
'navigation' => $navigation->getId(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Route("/navigation/{navigation}", name="admin_site_tree_navigation")
|
|
|
|
*/
|
|
|
|
public function navigation(
|
|
|
|
Navigation $navigation,
|
|
|
|
NavigationRepositoryQuery $navigationQuery,
|
|
|
|
MenuFactory $menuFactory
|
|
|
|
): Response {
|
|
|
|
$navigations = $navigationQuery->create()->find();
|
|
|
|
|
|
|
|
$forms = [
|
|
|
|
'menu' => $this->createForm(MenuType::class, $menuFactory->create())->createView(),
|
|
|
|
'menus' => [],
|
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($navigation->getMenus() as $menu) {
|
|
|
|
$forms['menus'][$menu->getId()] = $this->createForm(MenuType::class, $menu)->createView();
|
|
|
|
}
|
|
|
|
|
2021-03-23 21:49:56 +01:00
|
|
|
return $this->render('@Core/site/tree_admin/navigation.html.twig', [
|
2021-03-20 13:40:38 +01:00
|
|
|
'navigation' => $navigation,
|
|
|
|
'navigations' => $navigations,
|
|
|
|
'forms' => $forms,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSection(): string
|
|
|
|
{
|
|
|
|
return 'site_tree';
|
|
|
|
}
|
|
|
|
}
|