I am open this based from my question in my own comment from Static page dropdown within static page in OctoberCMS.
I have problem when adding $pageList->getPageTree(true). The child pages did not display. My current code is repeating foreach from $pageObject->subpages which is not a good practice.
Below here is my code example:
Plugin.php
<?php namespace MyPlugin\CustomPlugin
use System\Classes\PluginBase;
public function boot() {
\RainLab\Pages\Classes\Page::extend(function($model) {
$model->addDynamicMethod('getPageOptions', function() {
$theme = \Cms\Classes\Theme::getEditTheme();
$pageList = new \RainLab\Pages\Classes\PageList($theme);
$pages = [];
foreach ($pageList->getPageTree(true) as $name => $pageObject) {
$pages[$pageObject->page->url] = $pageObject->page->title;
if ($pageObject->subpages) {
foreach ($pageObject->subpages as $name => $pageObject) {
$pages[$pageObject->page->url] = ' ' . $pageObject->page->title;
if ($pageObject->subpages) {
foreach ($pageObject->subpages as $name => $pageObject) {
$pages[$pageObject->page->url] = ' ' . $pageObject->page->title;
}
}
}
}
}
return $pages;
});
});
}
Appreciate if anyone could help.