Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
[
'/<h' . $i . '([^>]*)>/i',
'/<\/h' . $i . '>/i'
],
[
'<h' . $newLevel . '$1>',
'</h' . $newLevel . '>'
],
$post->postContentFiltered
);
}
}

return $preparedPosts;
}

/**
* Prepare Data for accordion
* @param array $items Array of posts
Expand All @@ -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'])) {
Expand Down