Skip to content

Commit 9af2a64

Browse files
committed
also restore the modules within the layout object
1 parent 71d62a7 commit 9af2a64

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

src/EventListener/InheritArticleListener.php

+21-15
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class InheritArticleListener implements FrameworkAwareInterface
2525

2626
protected $columns;
2727
protected $sections;
28+
protected $modules;
2829
protected $db;
2930

3031
public function __construct(Connection $db)
@@ -38,9 +39,10 @@ public function onGetPageLayout(PageModel $pageModel, LayoutModel $layoutModel,
3839
$stringUtil = $this->framework->getAdapter(\Contao\StringUtil::class);
3940
$moduleModel = $this->framework->getAdapter(\Contao\ModuleModel::class);
4041

41-
// Reset the columns
42+
// Reset the cached data
4243
$this->columns = [];
4344
$this->sections = [];
45+
$this->modules = serialize([]);
4446

4547
// Initialize modules and sections
4648
$arrSections = ['header', 'left', 'right', 'main', 'footer'];
@@ -102,6 +104,7 @@ public function onGetPageLayout(PageModel $pageModel, LayoutModel $layoutModel,
102104
}
103105

104106
// Empty the modules in the layout
107+
$this->modules = $layoutModel->modules;
105108
$layoutModel->modules = serialize([]);
106109
}
107110

@@ -112,6 +115,8 @@ public function onGeneratePage(PageModel $pageModel, LayoutModel $layoutModel, P
112115
}
113116

114117
$pageRegular->Template->sections = $this->sections;
118+
119+
$layoutModel->modules = $this->modules;
115120
}
116121

117122
protected function getFrontendModule(PageModel $page, $module, string $column): string
@@ -122,34 +127,34 @@ protected function getFrontendModule(PageModel $page, $module, string $column):
122127
return $generatedModule;
123128
}
124129

125-
// initialize pid
130+
// Initialize pid
126131
$pid = $page->id;
127132

128-
// get all the parents
133+
// Get all the parents
129134
$parents = [];
130135

131-
// search for next parent ids while parent id > 0
136+
// Search for next parent ids while parent id > 0
132137
do {
133-
// get the next pid
138+
// Get the next pid
134139
$parent = $this->db->executeQuery('SELECT pid FROM tl_page WHERE id=?', [$pid])->fetch();
135140

136-
// if there are no parents anymore, break the loop
141+
// If there are no parents anymore, break the loop
137142
if (!$parent) {
138143
break;
139144
}
140145

141-
// get the parent id
146+
// Get the parent id
142147
$pid = $parent['pid'];
143148

144-
// store id
149+
// Store id
145150
$parents[] = $pid;
146151
} while ($pid);
147152

148-
// initialize rendered article modules
153+
// Initialize rendered article modules
149154
$renderedArticles = [];
150155
$renderedArticles[0] = $generatedModule;
151156

152-
// go through each parent
157+
// Go through each parent
153158
$level = 1;
154159
foreach ($parents as $pid) {
155160
$inheritArticles = $this->getInheritedArticles($pid, $column, $level);
@@ -160,19 +165,20 @@ protected function getFrontendModule(PageModel $page, $module, string $column):
160165
}
161166
}
162167

163-
// increase level
168+
// iIncrease level
164169
++$level;
165170
}
166171

167-
// sort by key
172+
// Sort by key
168173
krsort($renderedArticles);
169174

170-
// return combined articles
175+
// Return combined articles
171176
return implode('', $renderedArticles);
172177
}
173178

174179
protected function getInheritedArticles($pid, string $column, int $level): array
175180
{
181+
// Get adapters
176182
$controller = $this->framework->getAdapter(\Contao\Controller::class);
177183
$articleModel = $this->framework->getAdapter(\Contao\ArticleModel::class);
178184
$pageModel = $this->framework->getAdapter(\Contao\PageModel::class);
@@ -196,7 +202,7 @@ protected function getInheritedArticles($pid, string $column, int $level): array
196202
$renderedArticles = [];
197203

198204
if (null !== ($articles = $articleModel->findBy($columns, $values, $options))) {
199-
// override global page object
205+
// Override global page object
200206
global $objPage;
201207
$currentPage = $objPage;
202208
$objPage = $pageModel->findById($pid);
@@ -205,7 +211,7 @@ protected function getInheritedArticles($pid, string $column, int $level): array
205211
$renderedArticles[$article->inheritPriority] = $controller->getArticle($article->id, false, false, $column);
206212
}
207213

208-
// reset global page object
214+
// Reset global page object
209215
$objPage = $currentPage;
210216
}
211217

0 commit comments

Comments
 (0)