From 4298c2e2c7dc14f7aca3ddc914dc106ca15d95ed Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Thu, 29 Aug 2024 18:22:08 +1200 Subject: [PATCH] API Replace Extension subclasses --- docs/en/technical.md | 2 +- src/Extensions/BaseElementSubsites.php | 6 +++--- src/Extensions/ErrorPageSubsite.php | 6 +++--- src/Extensions/FileSubsites.php | 6 +++--- src/Extensions/GroupSubsites.php | 6 +++--- src/Extensions/LeftAndMainSubsites.php | 6 ++---- src/Extensions/SiteConfigSubsites.php | 6 +++--- src/Extensions/SiteTreeSubsites.php | 8 +++----- tests/php/FileSubsitesTest.php | 1 - tests/php/GroupSubsitesTest.php | 1 - tests/php/LeftAndMainSubsitesTest.php | 2 +- tests/php/SiteConfigSubsitesTest.php | 2 -- tests/php/SiteTreeSubsitesTest.php | 1 - 13 files changed, 22 insertions(+), 31 deletions(-) diff --git a/docs/en/technical.md b/docs/en/technical.md index 27bfbe4..3b1c198 100644 --- a/docs/en/technical.md +++ b/docs/en/technical.md @@ -9,7 +9,7 @@ page to a particular subsite. The subsite module adds functionality to the admin section of the site to allow you to create new subsites and copy pages between the main site and any subsites. -Subsites makes use of a DataExtension called SiteTreeSubsites to add support for subsites to the SiteTree, +Subsites makes use of an Extension called SiteTreeSubsites to add support for subsites to the SiteTree, which extends various methods to add Subsite functionality some of the methods are listed below ### augmentSQL diff --git a/src/Extensions/BaseElementSubsites.php b/src/Extensions/BaseElementSubsites.php index 40b3a43..214f303 100644 --- a/src/Extensions/BaseElementSubsites.php +++ b/src/Extensions/BaseElementSubsites.php @@ -4,14 +4,14 @@ namespace SilverStripe\Subsites\Extensions; use DNADesign\Elemental\Models\BaseElement; use SilverStripe\Control\HTTP; -use SilverStripe\ORM\DataExtension; +use SilverStripe\Core\Extension; /** * Extension for the BaseElement object to add subsites support for CMS previews * - * @extends DataExtension + * @extends Extension */ -class BaseElementSubsites extends DataExtension +class BaseElementSubsites extends Extension { /** * Set SubsiteID to avoid errors when a page doesn't exist on the CMS domain. diff --git a/src/Extensions/ErrorPageSubsite.php b/src/Extensions/ErrorPageSubsite.php index ab16cf1..245dce0 100644 --- a/src/Extensions/ErrorPageSubsite.php +++ b/src/Extensions/ErrorPageSubsite.php @@ -6,14 +6,14 @@ use SilverStripe\Assets\FileNameFilter; use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Core\Config\Config; use SilverStripe\ErrorPage\ErrorPage; -use SilverStripe\ORM\DataExtension; +use SilverStripe\Core\Extension; use SilverStripe\ORM\DataObject; use SilverStripe\Subsites\Model\Subsite; /** - * @extends DataExtension + * @extends Extension */ -class ErrorPageSubsite extends DataExtension +class ErrorPageSubsite extends Extension { /** * Alter file path to generated a static (static) error page file to handle error page template diff --git a/src/Extensions/FileSubsites.php b/src/Extensions/FileSubsites.php index b2e47f8..616a2fb 100644 --- a/src/Extensions/FileSubsites.php +++ b/src/Extensions/FileSubsites.php @@ -3,7 +3,7 @@ namespace SilverStripe\Subsites\Extensions; use SilverStripe\Assets\File; -use SilverStripe\ORM\DataExtension; +use SilverStripe\Core\Extension; use SilverStripe\ORM\DataQuery; use SilverStripe\ORM\Queries\SQLSelect; use SilverStripe\Security\Permission; @@ -15,9 +15,9 @@ use SilverStripe\Subsites\State\SubsiteState; * * @method Subsite Subsite() * - * @extends DataExtension + * @extends Extension */ -class FileSubsites extends DataExtension +class FileSubsites extends Extension { /** * If this is set to true, all folders created will be default be considered 'global', unless set otherwise diff --git a/src/Extensions/GroupSubsites.php b/src/Extensions/GroupSubsites.php index e214f3c..d66f8b6 100644 --- a/src/Extensions/GroupSubsites.php +++ b/src/Extensions/GroupSubsites.php @@ -8,7 +8,7 @@ use SilverStripe\Forms\CheckboxSetField; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\OptionsetField; use SilverStripe\Forms\ReadonlyField; -use SilverStripe\ORM\DataExtension; +use SilverStripe\Core\Extension; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataQuery; use SilverStripe\ORM\DB; @@ -24,9 +24,9 @@ use SilverStripe\Subsites\State\SubsiteState; * * @method ManyManyList Subsites() * - * @extends DataExtension + * @extends Extension */ -class GroupSubsites extends DataExtension implements PermissionProvider +class GroupSubsites extends Extension implements PermissionProvider { private static $db = [ 'AccessAllSubsites' => 'Boolean' diff --git a/src/Extensions/LeftAndMainSubsites.php b/src/Extensions/LeftAndMainSubsites.php index 2c9eb3b..fba1da8 100644 --- a/src/Extensions/LeftAndMainSubsites.php +++ b/src/Extensions/LeftAndMainSubsites.php @@ -6,13 +6,13 @@ use SilverStripe\Admin\AdminRootController; use SilverStripe\Admin\CMSMenu; use SilverStripe\Admin\CMSProfileController; use SilverStripe\Admin\LeftAndMain; -use SilverStripe\Admin\LeftAndMainExtension; use SilverStripe\CMS\Controllers\CMSPagesController; use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Controllers\CMSPageEditController; use SilverStripe\Control\Controller; use SilverStripe\Core\Config\Config; use SilverStripe\Core\Convert; +use SilverStripe\Core\Extension; use SilverStripe\Forms\HiddenField; use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\DataObject; @@ -27,10 +27,8 @@ use SilverStripe\View\Requirements; /** * Decorator designed to add subsites support to LeftAndMain - * - * @extends LeftAndMainExtension */ -class LeftAndMainSubsites extends LeftAndMainExtension +class LeftAndMainSubsites extends Extension { private static $allowed_actions = ['CopyToSubsite']; diff --git a/src/Extensions/SiteConfigSubsites.php b/src/Extensions/SiteConfigSubsites.php index 5125c82..5a17836 100644 --- a/src/Extensions/SiteConfigSubsites.php +++ b/src/Extensions/SiteConfigSubsites.php @@ -4,7 +4,7 @@ namespace SilverStripe\Subsites\Extensions; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\HiddenField; -use SilverStripe\ORM\DataExtension; +use SilverStripe\Core\Extension; use SilverStripe\ORM\DataQuery; use SilverStripe\ORM\Queries\SQLSelect; use SilverStripe\SiteConfig\SiteConfig; @@ -16,9 +16,9 @@ use SilverStripe\Subsites\State\SubsiteState; * * @method Subsite Subsite() * - * @extends DataExtension + * @extends Extension */ -class SiteConfigSubsites extends DataExtension +class SiteConfigSubsites extends Extension { private static $has_one = [ 'Subsite' => Subsite::class, // The subsite that this page belongs to diff --git a/src/Extensions/SiteTreeSubsites.php b/src/Extensions/SiteTreeSubsites.php index 923da7c..9857440 100644 --- a/src/Extensions/SiteTreeSubsites.php +++ b/src/Extensions/SiteTreeSubsites.php @@ -16,7 +16,7 @@ use SilverStripe\Forms\FormAction; use SilverStripe\Forms\ToggleCompositeField; use SilverStripe\i18n\i18n; use SilverStripe\ORM\ArrayList; -use SilverStripe\ORM\DataExtension; +use SilverStripe\Core\Extension; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataQuery; use SilverStripe\ORM\ManyManyList; @@ -37,9 +37,9 @@ use SilverStripe\VersionedAdmin\Controllers\HistoryViewerController; * @method ManyManyList CrossSubsiteLinkTracking() * @method Subsite Subsite() * - * @extends DataExtension + * @extends Extension */ -class SiteTreeSubsites extends DataExtension +class SiteTreeSubsites extends Extension { private static $has_one = [ 'Subsite' => Subsite::class, // The subsite that this page belongs to @@ -112,8 +112,6 @@ class SiteTreeSubsites extends DataExtension if (!$this->owner->ID && !$this->owner->SubsiteID) { $this->owner->SubsiteID = SubsiteState::singleton()->getSubsiteId(); } - - parent::onBeforeWrite(); } protected function updateCMSFields(FieldList $fields) diff --git a/tests/php/FileSubsitesTest.php b/tests/php/FileSubsitesTest.php index 15aa5fd..497bdba 100644 --- a/tests/php/FileSubsitesTest.php +++ b/tests/php/FileSubsitesTest.php @@ -17,7 +17,6 @@ class FileSubsitesTest extends BaseSubsiteTest public function testTrivialFeatures() { - $this->assertTrue(is_array(singleton(FileSubsites::class)->extraStatics())); $file = new File(); $file->Name = 'FileTitle'; $file->Title = 'FileTitle'; diff --git a/tests/php/GroupSubsitesTest.php b/tests/php/GroupSubsitesTest.php index 5a0b19e..5d1553b 100644 --- a/tests/php/GroupSubsitesTest.php +++ b/tests/php/GroupSubsitesTest.php @@ -15,7 +15,6 @@ class GroupSubsitesTest extends BaseSubsiteTest public function testTrivialFeatures() { - $this->assertIsArray(singleton(GroupSubsites::class)->extraStatics()); $this->assertIsArray(singleton(GroupSubsites::class)->providePermissions()); $this->assertInstanceOf(FieldList::class, singleton(Group::class)->getCMSFields()); } diff --git a/tests/php/LeftAndMainSubsitesTest.php b/tests/php/LeftAndMainSubsitesTest.php index c54a20e..f4d2320 100644 --- a/tests/php/LeftAndMainSubsitesTest.php +++ b/tests/php/LeftAndMainSubsitesTest.php @@ -109,6 +109,6 @@ class LeftAndMainSubsitesTest extends FunctionalTest /** @var LeftAndMain&LeftAndMainSubsites $leftAndMain */ $leftAndMain = new LeftAndMain(); - $this->assertTrue($leftAndMain->canAccess($member)); + $this->assertTrue($leftAndMain->alternateAccessCheck($member)); } } diff --git a/tests/php/SiteConfigSubsitesTest.php b/tests/php/SiteConfigSubsitesTest.php index 1631e29..b1a2662 100644 --- a/tests/php/SiteConfigSubsitesTest.php +++ b/tests/php/SiteConfigSubsitesTest.php @@ -15,8 +15,6 @@ class SiteConfigSubsitesTest extends BaseSubsiteTest $subsite1 = $this->objFromFixture(Subsite::class, 'domaintest1'); $subsite2 = $this->objFromFixture(Subsite::class, 'domaintest2'); - $this->assertTrue(is_array(singleton(SiteConfigSubsites::class)->extraStatics())); - Subsite::changeSubsite(0); $sc = SiteConfig::current_site_config(); $sc->Title = 'RootSite'; diff --git a/tests/php/SiteTreeSubsitesTest.php b/tests/php/SiteTreeSubsitesTest.php index fe2747b..b7e5956 100644 --- a/tests/php/SiteTreeSubsitesTest.php +++ b/tests/php/SiteTreeSubsitesTest.php @@ -92,7 +92,6 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest // The following assert is breaking in Translatable. $this->assertInstanceOf(FieldList::class, singleton(SiteTree::class)->getCMSFields()); $this->assertInstanceOf(FieldList::class, singleton(SubsitesVirtualPage::class)->getCMSFields()); - $this->assertTrue(is_array(singleton(SiteTreeSubsites::class)->extraStatics())); } public function errorPageLocationsProvider()