Jarves\PageStack::getRouteUrl PHP Method

getRouteUrl() public method

public getRouteUrl ( Node | integer $nodeOrId, boolean $suppressStartNodeCheck = false ) : string
$nodeOrId Jarves\Model\Node | integer
$suppressStartNodeCheck boolean
return string
    public function getRouteUrl($nodeOrId, $suppressStartNodeCheck = false)
    {
        $id = $nodeOrId;
        if (!$nodeOrId) {
            $nodeOrId = $this->getCurrentPage();
        }
        if ($nodeOrId instanceof Node) {
            $id = $nodeOrId->getId();
        }
        $domainId = $nodeOrId instanceof Node ? $nodeOrId->getDomainId() : $this->getDomainOfPage($id);
        $domain = $this->getCurrentDomain();
        if (!$domain || $domainId !== $domain->getId()) {
            $domain = $this->getDomain($domainId);
        }
        if (!$suppressStartNodeCheck && $domain->getStartnodeId() === $id) {
            $url = '/';
        } else {
            $urls = $this->getCachedPageToUrl($domainId);
            $url = isset($urls[$id]) ? $urls[$id] : '';
        }
        //crop first /
        if (substr($url, 0, 1) == '/') {
            $url = substr($url, 1);
        }
        if ($domain->getMaster() != 1) {
            $url = $domain->getPath() . $domain->getLang() . '/' . $url;
        } else {
            $url = $domain->getPath() . $url;
        }
        return $url;
    }

Usage Example

Beispiel #1
0
 public function registerPluginRoutes(Node $page)
 {
     $domain = $this->pageStack->getDomain($page->getDomainId());
     $this->stopwatch->start('Register Plugin Routes');
     //add all router to current router and fire sub-request
     $cacheKey = 'core/node/plugins-' . $page->getId();
     $plugins = $this->cacher->getDistributedCache($cacheKey);
     if (null === $plugins) {
         $plugins = ContentQuery::create()->filterByNodeId($page->getId())->filterByType('plugin')->find();
         $this->cacher->setDistributedCache($cacheKey, serialize($plugins));
     } else {
         $plugins = unserialize($plugins);
     }
     /** @var $plugins Content[] */
     foreach ($plugins as $plugin) {
         if (!$plugin->getContent()) {
             continue;
         }
         $data = json_decode($plugin->getContent(), true);
         if (!$data) {
             $this->logger->alert(sprintf('On page `%s` [%d] is a invalid plugin `%d`.', $page->getTitle(), $page->getId(), $plugin->getId()));
             continue;
         }
         $bundleName = isset($data['module']) ? $data['module'] : @$data['bundle'];
         $config = $this->jarves->getConfig($bundleName);
         if (!$config) {
             $this->logger->alert(sprintf('Bundle `%s` for plugin `%s` on page `%s` [%d] does not not exist.', $bundleName, @$data['plugin'], $page->getTitle(), $page->getId()));
             continue;
         }
         $pluginDefinition = $config->getPlugin(@$data['plugin']);
         if (!$pluginDefinition) {
             $this->logger->alert(sprintf('In bundle `%s` the plugin `%s` on page `%s` [%d] does not not exist.', $bundleName, @$data['plugin'], $page->getTitle(), $page->getId()));
             continue;
         }
         if ($pluginRoutes = $pluginDefinition->getRoutes()) {
             foreach ($pluginRoutes as $idx => $route) {
                 $controller = $pluginDefinition->getController();
                 $defaults = array('_controller' => $route->getController() ?: $controller, '_jarves_is_plugin' => true, '_content' => $plugin, '_title' => sprintf('%s: %s', $bundleName, $pluginDefinition->getLabel()), 'options' => isset($data['options']) && is_array($data['options']) ? $data['options'] : [], 'jarvesFrontend' => true, 'nodeId' => $page->getId());
                 if ($route->getDefaults()) {
                     $defaults = array_merge($defaults, $route->getArrayDefaults());
                 }
                 $url = $this->pageStack->getRouteUrl($page->getId());
                 $this->routes->add('jarves_frontend_plugin_' . ($route->getId() ?: $plugin->getId()) . '_' . $idx, new SyRoute($url . '/' . $route->getPattern(), $defaults, $route->getArrayRequirements() ?: array(), [], '', [], $route->getMethods() ?: []));
             }
         }
     }
     $this->stopwatch->stop('Register Plugin Routes');
 }