@@ -25,6 +25,7 @@ class InheritArticleListener implements FrameworkAwareInterface
25
25
26
26
protected $ columns ;
27
27
protected $ sections ;
28
+ protected $ modules ;
28
29
protected $ db ;
29
30
30
31
public function __construct (Connection $ db )
@@ -38,9 +39,10 @@ public function onGetPageLayout(PageModel $pageModel, LayoutModel $layoutModel,
38
39
$ stringUtil = $ this ->framework ->getAdapter (\Contao \StringUtil::class);
39
40
$ moduleModel = $ this ->framework ->getAdapter (\Contao \ModuleModel::class);
40
41
41
- // Reset the columns
42
+ // Reset the cached data
42
43
$ this ->columns = [];
43
44
$ this ->sections = [];
45
+ $ this ->modules = serialize ([]);
44
46
45
47
// Initialize modules and sections
46
48
$ arrSections = ['header ' , 'left ' , 'right ' , 'main ' , 'footer ' ];
@@ -102,6 +104,7 @@ public function onGetPageLayout(PageModel $pageModel, LayoutModel $layoutModel,
102
104
}
103
105
104
106
// Empty the modules in the layout
107
+ $ this ->modules = $ layoutModel ->modules ;
105
108
$ layoutModel ->modules = serialize ([]);
106
109
}
107
110
@@ -112,6 +115,8 @@ public function onGeneratePage(PageModel $pageModel, LayoutModel $layoutModel, P
112
115
}
113
116
114
117
$ pageRegular ->Template ->sections = $ this ->sections ;
118
+
119
+ $ layoutModel ->modules = $ this ->modules ;
115
120
}
116
121
117
122
protected function getFrontendModule (PageModel $ page , $ module , string $ column ): string
@@ -122,34 +127,34 @@ protected function getFrontendModule(PageModel $page, $module, string $column):
122
127
return $ generatedModule ;
123
128
}
124
129
125
- // initialize pid
130
+ // Initialize pid
126
131
$ pid = $ page ->id ;
127
132
128
- // get all the parents
133
+ // Get all the parents
129
134
$ parents = [];
130
135
131
- // search for next parent ids while parent id > 0
136
+ // Search for next parent ids while parent id > 0
132
137
do {
133
- // get the next pid
138
+ // Get the next pid
134
139
$ parent = $ this ->db ->executeQuery ('SELECT pid FROM tl_page WHERE id=? ' , [$ pid ])->fetch ();
135
140
136
- // if there are no parents anymore, break the loop
141
+ // If there are no parents anymore, break the loop
137
142
if (!$ parent ) {
138
143
break ;
139
144
}
140
145
141
- // get the parent id
146
+ // Get the parent id
142
147
$ pid = $ parent ['pid ' ];
143
148
144
- // store id
149
+ // Store id
145
150
$ parents [] = $ pid ;
146
151
} while ($ pid );
147
152
148
- // initialize rendered article modules
153
+ // Initialize rendered article modules
149
154
$ renderedArticles = [];
150
155
$ renderedArticles [0 ] = $ generatedModule ;
151
156
152
- // go through each parent
157
+ // Go through each parent
153
158
$ level = 1 ;
154
159
foreach ($ parents as $ pid ) {
155
160
$ inheritArticles = $ this ->getInheritedArticles ($ pid , $ column , $ level );
@@ -160,19 +165,20 @@ protected function getFrontendModule(PageModel $page, $module, string $column):
160
165
}
161
166
}
162
167
163
- // increase level
168
+ // iIncrease level
164
169
++$ level ;
165
170
}
166
171
167
- // sort by key
172
+ // Sort by key
168
173
krsort ($ renderedArticles );
169
174
170
- // return combined articles
175
+ // Return combined articles
171
176
return implode ('' , $ renderedArticles );
172
177
}
173
178
174
179
protected function getInheritedArticles ($ pid , string $ column , int $ level ): array
175
180
{
181
+ // Get adapters
176
182
$ controller = $ this ->framework ->getAdapter (\Contao \Controller::class);
177
183
$ articleModel = $ this ->framework ->getAdapter (\Contao \ArticleModel::class);
178
184
$ pageModel = $ this ->framework ->getAdapter (\Contao \PageModel::class);
@@ -196,7 +202,7 @@ protected function getInheritedArticles($pid, string $column, int $level): array
196
202
$ renderedArticles = [];
197
203
198
204
if (null !== ($ articles = $ articleModel ->findBy ($ columns , $ values , $ options ))) {
199
- // override global page object
205
+ // Override global page object
200
206
global $ objPage ;
201
207
$ currentPage = $ objPage ;
202
208
$ objPage = $ pageModel ->findById ($ pid );
@@ -205,7 +211,7 @@ protected function getInheritedArticles($pid, string $column, int $level): array
205
211
$ renderedArticles [$ article ->inheritPriority ] = $ controller ->getArticle ($ article ->id , false , false , $ column );
206
212
}
207
213
208
- // reset global page object
214
+ // Reset global page object
209
215
$ objPage = $ currentPage ;
210
216
}
211
217
0 commit comments