1 | <?php |
||
35 | class PageLayoutRenderer |
||
36 | { |
||
37 | /** |
||
38 | * @var bool Whether to force (or not force) embedding the content in the layout |
||
39 | */ |
||
40 | protected $use_layout; |
||
41 | |||
42 | /** |
||
43 | * @var Renderer |
||
44 | */ |
||
45 | protected $view_renderer; |
||
46 | |||
47 | /** |
||
48 | * @var \Request |
||
49 | */ |
||
50 | protected $current_request; |
||
51 | |||
52 | public function __construct(Renderer $view_renderer, \Request $current_request = NULL) |
||
53 | { |
||
54 | $this->view_renderer = $view_renderer; |
||
55 | $this->current_request = $current_request; |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * @param PageContentView $content_view |
||
60 | * |
||
61 | * @return string |
||
62 | */ |
||
63 | public function render(PageContentView $content_view) |
||
64 | { |
||
65 | $content = $this->view_renderer->render($content_view); |
||
66 | if ($this->shouldUseLayout()) { |
||
67 | return $this->renderInLayout($content_view->var_page(), $content); |
||
68 | } else { |
||
69 | return $content; |
||
70 | } |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @return bool |
||
75 | */ |
||
76 | protected function shouldUseLayout() |
||
88 | |||
89 | /** |
||
90 | * @param PageLayoutView $layout |
||
91 | * @param string $content |
||
92 | * |
||
93 | * @return string |
||
94 | */ |
||
95 | protected function renderInLayout(PageLayoutView $layout, $content) |
||
96 | { |
||
97 | $layout->setBodyHTML($content); |
||
98 | |||
99 | return $this->view_renderer->render($layout); |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * Configure whether to always wrap the content in the layout (TRUE), never (FALSE) or automatically for |
||
104 | * non-AJAX requests (NULL) |
||
105 | * |
||
106 | * @param bool $use_layout |
||
107 | * |
||
108 | * @return void |
||
109 | */ |
||
110 | public function setUseLayout($use_layout) |
||
114 | |||
115 | } |
||
116 |