From 3a37dcae6da7c717dd50f7b64ffe230679e9a801 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Wed, 31 Jul 2019 09:05:01 +1200 Subject: [PATCH] Revert "FIX Fluent now respects existing base URL prefixes in URL segment fields when no fluent domain exists" --- src/Extension/FluentSiteTreeExtension.php | 13 +++++++------ tests/php/Extension/FluentSiteTreeExtensionTest.php | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) 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());