Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX Fluent now respects existing base URL prefixes in URL segment fields when no fluent domain exists #523

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/Extension/FluentSiteTreeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ protected function addLocalePrefixToUrlSegment(FieldList $fields)
return $this;
}

// Mock frontend and get link to parent object / page
$baseURL = FluentState::singleton()
->withState(function (FluentState $tempState) {
// Mock frontend and set link to parent object / page
FluentState::singleton()
->withState(function (FluentState $tempState) use ($segmentField) {
$tempState->setIsDomainMode(true);
$tempState->setIsFrontend(true);

Expand All @@ -264,15 +264,14 @@ protected function addLocalePrefixToUrlSegment(FieldList $fields)
if ($domain) {
$parentBase = Controller::join_links($domain->Link(), Director::baseURL());
} else {
$parentBase = Director::absoluteBaseURL();
// Use any existing pre-configured base URL prefix for the field
$parentBase = $segmentField->getURLPrefix();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, the bug is that this link includes the parent url, whereas so does $parentRelative. It's adding parent urlsegment twice.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to revert this at #539

}

// Join base / relative links
return Controller::join_links($parentBase, $parentRelative);
$segmentField->setURLPrefix(Controller::join_links($parentBase, $parentRelative));
});


$segmentField->setURLPrefix($baseURL);
return $this;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/php/Extension/FluentSiteTreeExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ function (FluentState $newState) use ($localeCode, $fixture, $expected) {
$fields = $this->objFromFixture(Page::class, $fixture)->getCMSFields();

/** @var SiteTreeURLSegmentField $segmentField */
$segmentField = $fields->fieldByName('Root.Main.URLSegment');
$segmentField = $fields->dataFieldByName('URLSegment');
$this->assertInstanceOf(SiteTreeURLSegmentField::class, $segmentField);

$this->assertSame($expected, $segmentField->getURLPrefix());
Expand Down