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;
}