2021-03-24 12:27:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Core\Controller\Site;
|
|
|
|
|
|
|
|
use App\Core\Site\SiteRequest;
|
|
|
|
use App\Core\Site\SiteStore;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
|
|
|
|
class PageController extends AbstractController
|
|
|
|
{
|
|
|
|
protected SiteRequest $siteRequest;
|
|
|
|
protected SiteStore $siteStore;
|
|
|
|
|
|
|
|
public function __construct(SiteRequest $siteRequest, SiteStore $siteStore)
|
|
|
|
{
|
|
|
|
$this->siteRequest = $siteRequest;
|
|
|
|
$this->siteStore = $siteStore;
|
|
|
|
}
|
|
|
|
|
2021-03-29 14:18:42 +02:00
|
|
|
public function show(): Response
|
2021-03-24 12:27:07 +01:00
|
|
|
{
|
2021-03-29 14:18:42 +02:00
|
|
|
if (!$this->siteRequest->getPage()) {
|
2021-03-24 12:27:07 +01:00
|
|
|
throw $this->createNotFoundException();
|
|
|
|
}
|
|
|
|
|
2021-03-29 14:18:42 +02:00
|
|
|
return $this->defaultRender($this->siteRequest->getPage()->getTemplate());
|
2021-03-24 12:27:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function defaultRender(string $view, array $parameters = [], Response $response = null): Response
|
|
|
|
{
|
|
|
|
$parameters = array_merge($this->getDefaultRenderParameters(), $parameters);
|
|
|
|
|
|
|
|
return parent::render($view, $parameters, $response);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getDefaultRenderParameters(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'_node' => $this->siteRequest->getNode(),
|
|
|
|
'_page' => $this->siteRequest->getPage(),
|
|
|
|
'_menu' => $this->siteRequest->getMenu(),
|
|
|
|
'_navigation' => $this->siteRequest->getNavigation(),
|
|
|
|
'_store' => $this->siteStore,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|