|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
4
|
|
|
*/ |
|
5
|
|
|
namespace eZ\Publish\Core\MVC\Symfony\View\ParametersInjector; |
|
6
|
|
|
|
|
7
|
|
|
use eZ\Publish\Core\MVC\ConfigResolverInterface; |
|
8
|
|
|
use eZ\Publish\Core\MVC\Symfony\View\Event\FilterViewParametersEvent; |
|
9
|
|
|
use eZ\Publish\Core\MVC\Symfony\View\ViewEvents; |
|
10
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Injects the 'viewBaseLayout' view parameter, set by the container parameter. |
|
14
|
|
|
*/ |
|
15
|
|
|
class ViewbaseLayout implements EventSubscriberInterface |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
private $viewbaseLayout; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var \eZ\Publish\Core\MVC\ConfigResolverInterface |
|
24
|
|
|
*/ |
|
25
|
|
|
private $configResolver; |
|
26
|
|
|
|
|
27
|
|
|
public function __construct($viewbaseLayout, ConfigResolverInterface $configResolver) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->viewbaseLayout = $viewbaseLayout; |
|
30
|
|
|
$this->configResolver = $configResolver; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public static function getSubscribedEvents() |
|
34
|
|
|
{ |
|
35
|
|
|
return [ViewEvents::FILTER_VIEW_PARAMETERS => 'injectViewbaseLayout']; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
private function getPageLayout(): string |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->configResolver->hasParameter('page_layout') |
|
41
|
|
|
? $this->configResolver->getParameter('page_layout') |
|
42
|
|
|
: $this->configResolver->getParameter('pagelayout'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function injectViewbaseLayout(FilterViewParametersEvent $event) |
|
46
|
|
|
{ |
|
47
|
|
|
$pageLayout = $this->getPageLayout(); |
|
48
|
|
|
|
|
49
|
|
|
$event->getParameterBag()->set('view_base_layout', $this->viewbaseLayout); |
|
50
|
|
|
// @deprecated since 8.0. Use `page_layout` instead |
|
51
|
|
|
$event->getParameterBag()->set('pagelayout', $pageLayout); |
|
52
|
|
|
$event->getParameterBag()->set('page_layout', $pageLayout); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|