From e8d1db260de6d5a0576d4ce5d59064c25d1e2395 Mon Sep 17 00:00:00 2001 From: Samuele Masetto Date: Thu, 20 Oct 2016 15:11:39 +0200 Subject: [PATCH] Search in children subpage of modular I have created a recursive function to test if there is a modular page in parents. --- simplesearch.php | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) 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. */