12
12
13
13
namespace InheritArticleBundle \EventListener ;
14
14
15
- use Contao \CoreBundle \Framework \FrameworkAwareInterface ;
16
- use Contao \CoreBundle \Framework \ FrameworkAwareTrait ;
15
+ use Contao \CoreBundle \Framework \ContaoFramework ;
16
+ use Contao \CoreBundle \Image \ PictureFactory ;
17
17
use Contao \LayoutModel ;
18
18
use Contao \PageModel ;
19
19
use Contao \PageRegular ;
20
20
use Doctrine \DBAL \Connection ;
21
21
22
- class InheritArticleListener implements FrameworkAwareInterface
22
+ class InheritArticleListener
23
23
{
24
- use FrameworkAwareTrait;
25
-
24
+ /** @var array */
26
25
protected $ columns ;
26
+
27
+ /** @var array */
27
28
protected $ sections ;
29
+
30
+ /** @var string */
28
31
protected $ modules ;
32
+
33
+ /** @var Connection */
29
34
protected $ db ;
30
35
31
- public function __construct (Connection $ db )
36
+ /** @var ContaoFramework */
37
+ protected $ framework ;
38
+
39
+ /** @var PictureFactory */
40
+ protected $ pictureFactory ;
41
+
42
+ public function __construct (Connection $ db , ContaoFramework $ framework , PictureFactory $ pictureFactory )
32
43
{
33
44
$ this ->db = $ db ;
45
+ $ this ->framework = $ framework ;
46
+ $ this ->pictureFactory = $ pictureFactory ;
34
47
}
35
48
36
49
public function onGetPageLayout (PageModel $ pageModel , LayoutModel $ layoutModel , PageRegular $ pageRegular ): void
37
50
{
38
- $ this ->framework ->initialize ();
39
51
$ stringUtil = $ this ->framework ->getAdapter (\Contao \StringUtil::class);
40
52
$ moduleModel = $ this ->framework ->getAdapter (\Contao \ModuleModel::class);
41
53
@@ -62,6 +74,9 @@ public function onGetPageLayout(PageModel $pageModel, LayoutModel $layoutModel,
62
74
if (null !== $ objModules || 0 === $ arrModules [0 ]['mod ' ] || '0 ' === $ arrModules [0 ]['mod ' ]) { // see #4137
63
75
$ arrMapper = [];
64
76
77
+ // Set theme and layout related information in the page object (see #8)
78
+ $ this ->applyThemeAndLayout ($ pageModel , $ layoutModel );
79
+
65
80
// Create a mapper array in case a module is included more than once (see #4849)
66
81
if (null !== $ objModules ) {
67
82
while ($ objModules ->next ()) {
@@ -220,4 +235,21 @@ protected function getInheritedArticles($pid, string $column, int $level): array
220
235
221
236
return $ renderedArticles ;
222
237
}
238
+
239
+ /**
240
+ * Sets theme and layout related information in the page object,
241
+ * which is usually done by Contao after the getPageLayout hook.
242
+ */
243
+ protected function applyThemeAndLayout (PageModel $ page , LayoutModel $ layout ): void
244
+ {
245
+ /** @var \Contao\ThemeModel $theme */
246
+ $ theme = $ layout ->getRelated ('pid ' );
247
+ $ this ->pictureFactory ->setDefaultDensities ($ theme ->defaultImageDensities );
248
+ $ page ->layoutId = $ layout ->id ;
249
+ $ page ->template = $ layout ->template ?: 'fe_page ' ;
250
+ $ page ->templateGroup = $ theme ->templates ;
251
+ [$ strFormat , $ strVariant ] = explode ('_ ' , $ layout ->doctype );
252
+ $ page ->outputFormat = $ strFormat ;
253
+ $ page ->outputVariant = $ strVariant ;
254
+ }
223
255
}
0 commit comments