diff --git a/src/Extension/FluentSiteTreeExtension.php b/src/Extension/FluentSiteTreeExtension.php index 0a9cac65..e8afd72b 100644 --- a/src/Extension/FluentSiteTreeExtension.php +++ b/src/Extension/FluentSiteTreeExtension.php @@ -244,9 +244,9 @@ protected function addLocalePrefixToUrlSegment(FieldList $fields) return $this; } - // Mock frontend and set link to parent object / page - FluentState::singleton() - ->withState(function (FluentState $tempState) use ($segmentField) { + // Mock frontend and get link to parent object / page + $baseURL = FluentState::singleton() + ->withState(function (FluentState $tempState) { $tempState->setIsDomainMode(true); $tempState->setIsFrontend(true); @@ -264,14 +264,15 @@ protected function addLocalePrefixToUrlSegment(FieldList $fields) if ($domain) { $parentBase = Controller::join_links($domain->Link(), Director::baseURL()); } else { - // Use any existing pre-configured base URL prefix for the field - $parentBase = $segmentField->getURLPrefix(); + $parentBase = Director::absoluteBaseURL(); } // Join base / relative links - $segmentField->setURLPrefix(Controller::join_links($parentBase, $parentRelative)); + return Controller::join_links($parentBase, $parentRelative); }); + + $segmentField->setURLPrefix($baseURL); return $this; } diff --git a/tests/php/Extension/FluentSiteTreeExtensionTest.php b/tests/php/Extension/FluentSiteTreeExtensionTest.php index 53691280..c5eaa694 100644 --- a/tests/php/Extension/FluentSiteTreeExtensionTest.php +++ b/tests/php/Extension/FluentSiteTreeExtensionTest.php @@ -316,7 +316,7 @@ function (FluentState $newState) use ($localeCode, $fixture, $expected) { $fields = $this->objFromFixture(Page::class, $fixture)->getCMSFields(); /** @var SiteTreeURLSegmentField $segmentField */ - $segmentField = $fields->dataFieldByName('URLSegment'); + $segmentField = $fields->fieldByName('Root.Main.URLSegment'); $this->assertInstanceOf(SiteTreeURLSegmentField::class, $segmentField); $this->assertSame($expected, $segmentField->getURLPrefix());