public function getFullPath()
{
// check if this document is also the site root, if so return /
try {
if (\Pimcore\Tool::isFrontend() && Site::isSiteRequest()) {
$site = Site::getCurrentSite();
if ($site instanceof Site) {
if ($site->getRootDocument()->getId() == $this->getId()) {
$link = $this->prepareFrontendPath("/");
return $link;
}
}
}
} catch (\Exception $e) {
Logger::error($e);
}
// @TODO please forgive me, this is the dirtiest hack I've ever made :(
// if you got confused by this functionality drop me a line and I'll buy you some beers :)
// this is for the case that a link points to a document outside of the current site
// in this case we look for a hardlink in the current site which points to the current document
// why this could happen: we have 2 sites, in one site there's a hardlink to the other site and on a page inside
// the hardlink there are snippets embedded and this snippets have links pointing to a document which is also
// inside the hardlink scope, but this is an ID link, so we cannot rewrite the link the usual way because in the
// snippet / link we don't know anymore that whe a inside a hardlink wrapped document
if (\Pimcore\Tool::isFrontend() && Site::isSiteRequest() && !FrontendTool::isDocumentInCurrentSite($this)) {
$documentService = new Document\Service();
$parent = $this;
while ($parent) {
if ($hardlinkId = $documentService->getDocumentIdFromHardlinkInSameSite(Site::getCurrentSite(), $parent)) {
$hardlink = Document::getById($hardlinkId);
if (FrontendTool::isDocumentInCurrentSite($hardlink)) {
$siteRootPath = Site::getCurrentSite()->getRootPath();
$siteRootPath = preg_quote($siteRootPath);
$hardlinkPath = preg_replace("@^" . $siteRootPath . "@", "", $hardlink->getRealFullPath());
$link = preg_replace("@^" . preg_quote($parent->getRealFullPath()) . "@", $hardlinkPath, $this->getRealFullPath());
$link = $this->prepareFrontendPath($link);
return $link;
}
}
$parent = $parent->getParent();
}
$config = \Pimcore\Config::getSystemConfig();
$front = \Zend_Controller_Front::getInstance();
$scheme = ($front->getRequest()->isSecure() ? "https" : "http") . "://";
if ($site = FrontendTool::getSiteForDocument($this)) {
if ($site->getMainDomain()) {
// check if current document is the root of the different site, if so, preg_replace below doesn't work, so just return /
if ($site->getRootDocument()->getId() == $this->getId()) {
$link = $scheme . $site->getMainDomain() . "/";
$link = $this->prepareFrontendPath($link);
return $link;
}
$link = $scheme . $site->getMainDomain() . preg_replace("@^" . $site->getRootPath() . "/@", "/", $this->getRealFullPath());
$link = $this->prepareFrontendPath($link);
return $link;
}
}
if ($config->general->domain) {
$link = $scheme . $config->general->domain . $this->getRealFullPath();
$link = $this->prepareFrontendPath($link);
return $link;
}
}
$path = $this->getPath() . $this->getKey();
$path = $this->prepareFrontendPath($path);
return $path;
}