diff --git a/source/php/Module/Posts/TemplateController/ExpandableListTemplate.php b/source/php/Module/Posts/TemplateController/ExpandableListTemplate.php index ca0e72d63..2c1ab0edd 100644 --- a/source/php/Module/Posts/TemplateController/ExpandableListTemplate.php +++ b/source/php/Module/Posts/TemplateController/ExpandableListTemplate.php @@ -81,6 +81,44 @@ public function getColumnValues(): array return $columnValues; } + /** + * Rewrite post content headings to fit into accordion structure + * + * @param array $preparedPosts Array of prepared posts + * + * @return array + */ + private function rewritePostContent($preparedPosts): array + { + $rewrittenPosts = []; + + $increment = empty($this->module->hideTitle) && !empty($this->data['post_title']) ? 2 : 1; + + foreach ($preparedPosts as &$post) { + for ($i = 5; $i >= 1; $i--) { + $newLevel = $i + $increment; + + if ($newLevel > 6) { + $newLevel = 6; + } + + $post->postContentFiltered = preg_replace( + [ + '/]*)>/i', + '/<\/h' . $i . '>/i' + ], + [ + '', + '' + ], + $post->postContentFiltered + ); + } + } + + return $preparedPosts; + } + /** * Prepare Data for accordion * @param array $items Array of posts @@ -92,7 +130,7 @@ public function prepareExpandableList(): ?array { $accordion = []; - $this->data['posts'] = $this->preparePosts($this->module); + $this->data['posts'] = $this->rewritePostContent($this->preparePosts($this->module)); $columnValues = $this->getColumnValues(); if (!empty($this->data['posts']) && is_array($this->data['posts'])) {