src/Route/CmsPageRouter.php
protected function generateFromPage(PageInterface $page, array $parameters = [], $referenceType = self::ABSOLUTE_PATH)
    {
        // hybrid pages use, by definition, the default routing mechanism
        if ($page->isHybrid()) {
            return $this->router->generate($page->getRouteName(), $parameters, $referenceType);
        }

        $url = $this->getUrlFromPage($page);

        if (false === $url) {
            throw new \RuntimeException(sprintf('Page "%d" has no url or customUrl.', $page->getId()));
        }

        // NEXT_MAJOR: remove this if block
        if (!$this->context instanceof SiteRequestContextInterface) {
            @trigger_error(
                sprintf('Since, 3.3 when calling %s, %s::$context should implement SiteRequestContextInterface. This will become mandatory in 4.0.', __METHOD__, __CLASS__),
                E_USER_DEPRECATED
            );

            return $this->decorateUrl($url, $parameters, $referenceType);
        }

        // Get current site
        $currentSite = $this->context->getSite();
        // Change to new site
        $this->context->setSite($page->getSite());
        // Fetch Url
        $decoratedUrl = $this->decorateUrl($url, $parameters, $referenceType);
        // Swap back to original site
        $this->context->setSite($currentSite);

        return $decoratedUrl;
    }
protected function generateFromPage(PageInterface $page, array $parameters = [], $referenceType = self::ABSOLUTE_PATH)
    {
        // hybrid pages use, by definition, the default routing mechanism
        if ($page->isHybrid()) {
            return $this->router->generate($page->getRouteName(), $parameters, $referenceType);
        }

        $url = $this->getUrlFromPage($page);

        if (false === $url) {
            throw new \RuntimeException(sprintf('Page "%d" has no url or customUrl.', $page->getId()));
        }

        // NEXT_MAJOR: remove this if block
        if (!$this->context instanceof SiteRequestContextInterface) {
            @trigger_error(
                sprintf('Since, 3.3 when calling %s, %s::$context should implement SiteRequestContextInterface. This will become mandatory in 4.0.', __METHOD__, __CLASS__),
                E_USER_DEPRECATED
            );

            return $this->decorateUrl($url, $parameters, $referenceType);
        }

        // Get current site
        $currentSite = $this->context->getSite();
        // Change to new site
        $this->context->setSite($page->getSite());
        // Fetch Url
        $decoratedUrl = $this->decorateUrl($url, $parameters, $referenceType);
        // Swap back to original site
        $this->context->setSite($currentSite);

        return $decoratedUrl;
    }
protected function generateFromPage ( PageInterface $ page , array $ parameters = [ ] , $ referenceType = self :: ABSOLUTE_PATH ) { // hybrid pages use, by definition, the default routing mechanism if ( $ page -> isHybrid ( ) ) { return $ this -> router -> generate ( $ page -> getRouteName ( ) , $ parameters , $ referenceType ) ; } $ url = $ this -> getUrlFromPage ( $ page ) ; if ( false === $ url ) { throw new \ RuntimeException ( sprintf ( 'Page "%d" has no url or customUrl.' , $ page -> getId ( ) ) ) ; } // NEXT_MAJOR: remove this if block if ( ! $ this -> context instanceof SiteRequestContextInterface ) { @ trigger_error ( sprintf ( 'Since, 3.3 when calling %s, %s::$context should implement SiteRequestContextInterface. This will become mandatory in 4.0.' , __METHOD__ , __CLASS__ ) , E_USER_DEPRECATED ) ; return $ this -> decorateUrl ( $ url , $ parameters , $ referenceType ) ; } // Get current site $ currentSite = $ this -> context -> getSite ( ) ; // Change to new site $ this -> context -> setSite ( $ page -> getSite ( ) ) ; // Fetch Url $ decoratedUrl = $ this -> decorateUrl ( $ url , $ parameters , $ referenceType ) ; // Swap back to original site $ this -> context -> setSite ( $ currentSite ) ; return $ decoratedUrl ; }
Generates an URL from a Page object.
We swap site context to make sure the right context is used when generating the url.

@param PageInterface $page          Page object
@param array         $parameters    An array of parameters
@param bool|string   $referenceType The type of reference to be generated (one of the constants)

@throws \RuntimeException

@return string
Generates an URL from a Page object . We swap site context to make sure the right context is used when generating the url .