From 3b8207d70cb98c42f1fdf204e815a0a078fdaa5e Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Fri, 31 May 2019 10:28:36 +1200 Subject: [PATCH 1/3] Ensure URL segment field type before using its API, and add docs around subsite and fluent domain compatibility --- docs/en/introduction.md | 11 +++++++++++ src/Extensions/SiteTreeSubsites.php | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/en/introduction.md b/docs/en/introduction.md index 24eabff..e9dba82 100644 --- a/docs/en/introduction.md +++ b/docs/en/introduction.md @@ -48,3 +48,14 @@ to speak to your website administrator or hosting provider to facilitate this. You can simulate subsite access without setting up virtual hosts by appending ?SubsiteID= to the request. + +### How do Subsite domains work with Fluent domains? + +The Subsites module and Fluent translation module both provide the concept of defining "domains" and let you +configure the host name for it. This functionality is essentially performing the same duty in both modules. + +In the "URL segment" field for CMS pages both Subsites and Fluent will add their context to the value. If you +have a Subsite domain configured but no Fluent domain, Fluent will respect the existing domain and add its +locale context to the value. If you have a Subsite domain configured and a Fluent domain configure, Fluent will +use its own domain host name value, and the Subsite domain value will be lost. For this reason, you will need +to ensure that you use the same host name in both Subsite and Fluent domain entries. diff --git a/src/Extensions/SiteTreeSubsites.php b/src/Extensions/SiteTreeSubsites.php index 728feca..ed79f98 100644 --- a/src/Extensions/SiteTreeSubsites.php +++ b/src/Extensions/SiteTreeSubsites.php @@ -3,6 +3,7 @@ namespace SilverStripe\Subsites\Extensions; use Page; +use SilverStripe\CMS\Forms\SiteTreeURLSegmentField; use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Control\Controller; use SilverStripe\Control\Director; @@ -150,6 +151,7 @@ class SiteTreeSubsites extends DataExtension // replace readonly link prefix $subsite = $this->owner->Subsite(); $nested_urls_enabled = Config::inst()->get(SiteTree::class, 'nested_urls'); + /** @var Subsite $subsite */ if ($subsite && $subsite->exists()) { // Use baseurl from domain $baseLink = $subsite->absoluteBaseURL(); @@ -163,7 +165,7 @@ class SiteTreeSubsites extends DataExtension } $urlsegment = $fields->dataFieldByName('URLSegment'); - if ($urlsegment) { + if ($urlsegment && $urlsegment instanceof SiteTreeURLSegmentField) { $urlsegment->setURLPrefix($baseLink); } } From 2b268765965568f929b04ee98c857a2a06678a98 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Fri, 31 May 2019 16:41:36 +1200 Subject: [PATCH 2/3] Add test for URLSegment prefix set to primary subsite domain for page --- tests/php/SiteTreeSubsitesTest.php | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/tests/php/SiteTreeSubsitesTest.php b/tests/php/SiteTreeSubsitesTest.php index d165336..dc54afa 100644 --- a/tests/php/SiteTreeSubsitesTest.php +++ b/tests/php/SiteTreeSubsitesTest.php @@ -5,10 +5,10 @@ namespace SilverStripe\Subsites\Tests; use Page; use SilverStripe\CMS\Controllers\CMSMain; use SilverStripe\CMS\Controllers\ModelAsController; +use SilverStripe\CMS\Forms\SiteTreeURLSegmentField; use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Control\Director; use SilverStripe\Core\Config\Config; -use SilverStripe\Core\Convert; use SilverStripe\ErrorPage\ErrorPage; use SilverStripe\Forms\FieldList; use SilverStripe\Security\Member; @@ -21,6 +21,7 @@ use SilverStripe\Subsites\Tests\SiteTreeSubsitesTest\TestClassB; use SilverStripe\Subsites\Tests\SiteTreeSubsitesTest\TestErrorPage; use SilverStripe\Versioned\Versioned; use SilverStripe\View\SSViewer; +use TractorCow\Fluent\Extension\FluentSiteTreeExtension; class SiteTreeSubsitesTest extends BaseSubsiteTest { @@ -33,7 +34,9 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest ]; protected static $illegal_extensions = [ - SiteTree::class => ['Translatable'] // @todo implement Translatable namespace + SiteTree::class => [ + FluentSiteTreeExtension::class, + ], ]; protected function setUp() @@ -449,7 +452,7 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest /** * @dataProvider provideAlternateAbsoluteLink - * @param name $pageFixtureName + * @param string $pageFixtureName * @param string|null $action * @param string $expectedAbsoluteLink */ @@ -465,4 +468,23 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest $this->assertEquals($expectedAbsoluteLink, $result); } + + public function testURLSegmentBaseIsSetToSubsiteBaseURL() + { + // This subsite has a domain with 'one.example.org' as the primary domain + /** @var Subsite $subsite */ + $subsite = $this->objFromFixture(Subsite::class, 'domaintest1'); + Subsite::changeSubsite($subsite); + + $page = new SiteTree(); + $page->SubsiteID = $subsite->ID; + $page->write(); + $fields = $page->getCMSFields(); + + /** @var SiteTreeURLSegmentField $urlSegmentField */ + $urlSegmentField = $fields->dataFieldByName('URLSegment'); + $this->assertInstanceOf(SiteTreeURLSegmentField::class, $urlSegmentField); + + $this->assertSame('http://one.example.org/', $urlSegmentField->getURLPrefix()); + } } From f6503822e8bd55edeb444bf9e988308163f3ec7a Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Wed, 5 Jun 2019 15:09:57 +1200 Subject: [PATCH 3/3] DOCS Fix typos [ci skip] Co-Authored-By: Garion Herman --- docs/en/introduction.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/introduction.md b/docs/en/introduction.md index e9dba82..66bf7e6 100644 --- a/docs/en/introduction.md +++ b/docs/en/introduction.md @@ -54,8 +54,8 @@ You can simulate subsite access without setting up virtual hosts by appending ?S The Subsites module and Fluent translation module both provide the concept of defining "domains" and let you configure the host name for it. This functionality is essentially performing the same duty in both modules. -In the "URL segment" field for CMS pages both Subsites and Fluent will add their context to the value. If you +In the "URL segment" field for CMS pages, both Subsites and Fluent will add their context to the value. If you have a Subsite domain configured but no Fluent domain, Fluent will respect the existing domain and add its -locale context to the value. If you have a Subsite domain configured and a Fluent domain configure, Fluent will +locale context to the value. If you have a Subsite domain configured and a Fluent domain configured, Fluent will use its own domain host name value, and the Subsite domain value will be lost. For this reason, you will need to ensure that you use the same host name in both Subsite and Fluent domain entries.