private function buildMenu(ItemInterface $rootMenu, Page $page, array $options) { $titleGetter = 'get' . ucfirst($options['title_property']); $menu = $rootMenu->addChild($page->{$titleGetter}())->setAttribute('id', $page->getId()); if ($options['root_as_child']) { $menu->addChild($page->{$titleGetter}())->setUri($page->getMainUrl())->setAttribute('id', $page->getId()); } foreach ($page->getChildren() as $childPage) { $menu->addChild($childPage->{$titleGetter}())->setUri($childPage->getMainUrl())->setAttribute('id', $childPage->getId()); } }