1 | <?php |
||
18 | class Layout extends AbstractListenerAggregate implements PluginInterface |
||
19 | { |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $layoutTemplate = 'mail/layout.phtml'; |
||
25 | |||
26 | /** |
||
27 | * @param ComposerEvent $event |
||
28 | */ |
||
29 | 3 | public function injectLayoutViewModel(ComposerEvent $event) |
|
30 | { |
||
31 | 3 | $currentViewModel = $event->getViewModel(); |
|
32 | // don't render layout if ViewModel says so |
||
33 | 3 | if ($currentViewModel->terminate()) { |
|
34 | 1 | return; |
|
35 | } |
||
36 | 2 | $layoutModel = new ViewModel(); |
|
37 | 2 | $layoutModel->addChild($currentViewModel); |
|
38 | |||
39 | 2 | if ($event->getTemplate() instanceof LayoutProviderInterface) { |
|
40 | 1 | $layout = $event->getTemplate()->getLayout(); |
|
41 | } else { |
||
42 | 1 | $layout = $this->layoutTemplate; |
|
43 | } |
||
44 | |||
45 | 2 | $layoutModel->setTemplate($layout); |
|
46 | 2 | $event->setViewModel($layoutModel); |
|
47 | 2 | } |
|
48 | |||
49 | /** |
||
50 | * Attach one or more listeners |
||
51 | * |
||
52 | * Implementors may add an optional $priority argument; the EventManager |
||
53 | * implementation will pass this to the aggregate. |
||
54 | * |
||
55 | * @param EventManagerInterface $events |
||
56 | * |
||
57 | * @return void |
||
58 | */ |
||
59 | public function attach(EventManagerInterface $events, $priority = 1) |
||
63 | |||
64 | /** |
||
65 | * @param string $layoutTemplate |
||
66 | * @return self |
||
67 | */ |
||
68 | 2 | public function setLayoutTemplate($layoutTemplate) |
|
74 | |||
75 | /** |
||
76 | * @return string |
||
77 | */ |
||
78 | 2 | public function getLayoutTemplate() |
|
82 | } |
||
83 |