1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Superdesk Web Publisher Web Renderer Bundle. |
5
|
|
|
* |
6
|
|
|
* Copyright 2015 Sourcefabric z.u. and contributors. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please see the |
9
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @copyright 2015 Sourcefabric z.ú. |
12
|
|
|
* @license http://www.superdesk.org/license |
13
|
|
|
*/ |
14
|
|
|
namespace SWP\Bundle\WebRendererBundle\Controller; |
15
|
|
|
|
16
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
17
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
18
|
|
|
use Symfony\Component\HttpFoundation\Request; |
19
|
|
|
|
20
|
|
|
class ContentController extends Controller |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Render content Page. |
24
|
|
|
*/ |
25
|
|
|
public function renderContentPageAction(Request $request, $contentDocument) |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
return $this->renderPage('content', ['article' => $contentDocument]); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Render container Page. |
32
|
|
|
*/ |
33
|
|
|
public function renderContainerPageAction(Request $request, $slug) |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
return $this->renderPage('container', ['slug' => $slug]); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Render Page. |
40
|
|
|
* |
41
|
|
|
* @param string $type |
42
|
|
|
* @param array $parameters |
43
|
|
|
*/ |
44
|
|
|
private function renderPage($type, $parameters = []) |
45
|
|
|
{ |
46
|
|
|
$context = $this->container->get('context'); |
47
|
|
|
$metaLoader = $this->container->get('swp_template_engine_loader_chain'); |
48
|
|
|
$article = null; |
49
|
|
|
|
50
|
|
|
if ($type == 'content' && !is_null($parameters['article'])) { |
51
|
|
|
$article = $metaLoader->load('article', ['article' => $parameters['article']]); |
52
|
|
|
} elseif ($type == 'container') { |
53
|
|
|
$article = $metaLoader->load('article', $parameters); |
54
|
|
|
|
55
|
|
|
if (!$article) { |
56
|
|
|
throw new NotFoundHttpException('Requested page was not found'); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
if ($article) { |
61
|
|
|
$context->registerMeta('article', $article); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$tenantContext = $this->get('swp_multi_tenancy.tenant_context'); |
65
|
|
|
|
66
|
|
|
return $this->render('article.html.twig', [ |
67
|
|
|
'tenant' => $tenantContext->getTenant(), |
68
|
|
|
]); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.