diff --git a/code/model/SiteTree.php b/code/model/SiteTree.php index 264da89f..239e885a 100644 --- a/code/model/SiteTree.php +++ b/code/model/SiteTree.php @@ -462,22 +462,19 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid public function RelativeLink($action = null) { if($this->ParentID && self::config()->nested_urls) { $base = $this->Parent()->RelativeLink($this->URLSegment); + } elseif(!$action && $this->URLSegment == RootURLController::get_homepage_link()) { + // Unset base for root-level homepages. + // Note: Homepages with action parameters (or $action === true) + // need to retain their URLSegment. + $base = null; } else { $base = $this->URLSegment; } - // Unset base for homepage URLSegments in their default language. - // Homepages with action parameters or in different languages - // need to retain their URLSegment. We can only do this if the homepage - // is on the root level. - if(!$action && $base == RootURLController::get_homepage_link() && !$this->ParentID) { - $base = null; - if(class_exists('Translatable') && $this->hasExtension('Translatable') && $this->Locale != Translatable::default_locale()){ - $base = $this->URLSegment; - } - } + $this->extend('updateRelativeLink', $base, $action); - // Legacy support + // Legacy support: If $action === true, retain URLSegment for homepages, + // but don't append any action if($action === true) $action = null; return Controller::join_links($base, '/', $action); diff --git a/code/model/SiteTreeExtension.php b/code/model/SiteTreeExtension.php index c800398f..f033e8ff 100644 --- a/code/model/SiteTreeExtension.php +++ b/code/model/SiteTreeExtension.php @@ -1,4 +1,5 @@