Jarves\PageStack::getNodeUrl PHP Méthode

getNodeUrl() public méthode

public getNodeUrl ( Node | integer | string $nodeOrId, boolean $fullUrl = false, boolean $suppressStartNodeCheck = false ) : string
$nodeOrId Jarves\Model\Node | integer | string
$fullUrl boolean with http://
$suppressStartNodeCheck boolean
Résultat string
    public function getNodeUrl($nodeOrId, $fullUrl = false, $suppressStartNodeCheck = false)
    {
        $domain = $this->getCurrentDomain();
        $url = null;
        $id = null;
        if (is_string($nodeOrId) && !is_numeric($nodeOrId)) {
            $url = $nodeOrId;
        } else {
            $node = $nodeOrId;
            if (!$nodeOrId) {
                $node = $this->getCurrentPage();
            } else {
                if (is_numeric($nodeOrId)) {
                    $node = $this->getPage($nodeOrId);
                }
            }
            $id = $node->getId();
            $domainId = $node->getDomainId();
            if ($domainId && (!$domain || $domainId !== $domain->getId())) {
                $domain = $this->getDomain($domainId);
            }
            if (!$suppressStartNodeCheck && $domain->getStartnodeId() && $domain->getStartnodeId() === $id) {
                $url = '/';
            } else {
                if (!$node->getId()) {
                    //dynamic created Nodes need to define the full url as urn since it does not have parents
                    //nor do we get the full url from getCachedPageToUrl().
                    $url = $node->getUrn();
                } else {
                    $urls = $this->getCachedPageToUrl($domainId);
                    $url = isset($urls[$id]) ? $urls[$id] : '';
                }
                if (!$url && !$id) {
                    throw new \InvalidArgumentException('Requested url for page that does not have an id and no urn.');
                }
            }
        }
        //do we need to add app_dev.php/ or something?
        $prefix = '';
        if ($request = $this->getRequest()) {
            $prefix = substr($request->getBaseUrl(), strlen($request->getBasePath()));
        }
        if (false !== $prefix) {
            $url = substr($prefix, 1) . $url;
        }
        //crop first /
        if (substr($url, 0, 1) == '/') {
            $url = substr($url, 1);
        }
        if ($fullUrl) {
            $domainName = $this->getRequest()->getHttpHost();
            if ($domain) {
                $domainName = $domain->getRealDomain();
            }
            $isSecure = $this->getRequest() ? $this->getRequest()->isSecure() : false;
            $url = 'http' . ($isSecure ? 's' : '') . '://' . $domainName . $url;
        } else {
            //check that we have first starting slash
            if ('/' !== substr($url, 0, 1)) {
                $url = '/' . $url;
            }
        }
        //crop last /
        if (substr($url, -1) == '/') {
            $url = substr($url, 0, -1);
        }
        return $url;
    }

Usage Example

Exemple #1
0
 public function populateRow($clazz, $row, $selects, $relations, $relationFields, $permissionCheck = false)
 {
     $row = parent::populateRow($clazz, $row, $selects, $relations, $relationFields, $permissionCheck);
     if ($row) {
         $row['url'] = $this->pageStack->getNodeUrl($row['id']);
     }
     return $row;
 }
All Usage Examples Of Jarves\PageStack::getNodeUrl