diff --git a/simplesearch.php b/simplesearch.php index d8a6587..2f72316 100644 --- a/simplesearch.php +++ b/simplesearch.php @@ -171,12 +171,10 @@ public function onPagesInitialized() continue; } - if ($cpage->modular()) { - $this->collection->remove($cpage); - $parent = $cpage->parent(); + $parent = $this->getModularParent($cpage, $cpage); + if ($parent) $extras[$parent->path()] = ['slug' => $parent->slug()]; - } - + } } } @@ -212,7 +210,25 @@ public function onPagesInitialized() } } - + /** + * Test if there is modular in page parents and get modular page + * + * @param Page $cpage Page object to perform test if it is modular + * @param Page $leafPage Original page + * + * @return Page Modular page parent or null + */ + protected function getModularParent($cpage, $leafPage) { + $parent = null; + if ($cpage->modular()) { + $this->collection->remove($leafPage); + $parent = $cpage->parent(); + } elseif ($cpage->parent()) { + $parent = $this->getModularParent($cpage->parent(), $cpage); + } + return $parent; + } + /** * Set needed variables to display the search results. */