public function iterate($menu, PageInterface $page)
 {
     foreach ($page->getChildren() as $page) {
         if ($page->isHybrid() || !$page->getUrl()) {
             continue;
         }
         $menu->addChild($page->getName(), array('route' => $page->getRouteName(), 'routeParameters' => array('path' => $page->getUrl())));
         if ($page->getChildren()) {
             $this->iterate($menu[$page->getName()], $page);
         }
     }
 }
示例#2
0
 /**
  * @throws \RunTimeException
  * @param null|\Sonata\PageBundle\Model\PageInterface|string $page
  * @param bool $absolute
  * @return string
  */
 public function url($page = null, $absolute = false)
 {
     if (!$page) {
         return '';
     }
     $context = $this->router->getContext();
     if ($page instanceof PageInterface) {
         if ($page->isDynamic()) {
             if ($this->environment->isDebug()) {
                 throw new \RunTimeException('Unable to generate path for dynamic page');
             }
             return '';
         }
         $url = $page->getCustomUrl() ?: $page->getUrl();
     } else {
         $url = $page;
     }
     $url = sprintf('%s%s', $context->getBaseUrl(), $url);
     if ($absolute && $context->getHost()) {
         $scheme = $context->getScheme();
         $port = '';
         if ('http' === $scheme && 80 != $context->getHttpPort()) {
             $port = ':' . $context->getHttpPort();
         } elseif ('https' === $scheme && 443 != $context->getHttpsPort()) {
             $port = ':' . $context->getHttpsPort();
         }
         $url = $scheme . '://' . $context->getHost() . $port . $url;
     }
     return $url;
 }
 /**
  * Returns the Url from a Page object.
  *
  * @param PageInterface $page
  *
  * @return string
  */
 protected function getUrlFromPage(PageInterface $page)
 {
     return $page->getCustomUrl() ?: $page->getUrl();
 }