From a46ca42880913a18e84160007e608bd0027fc81e Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Thu, 17 Oct 2024 13:13:17 +1300 Subject: [PATCH] API Update code to reflect changes to LeftAndMain --- _config/extensions.yml | 4 ---- src/Extensions/LeftAndMainSubsites.php | 14 +++----------- src/Model/Subsite.php | 3 ++- tests/php/SiteTreeSubsitesTest.php | 4 ++-- 4 files changed, 7 insertions(+), 18 deletions(-) diff --git a/_config/extensions.yml b/_config/extensions.yml index 8d4b0a57..36ece43c 100644 --- a/_config/extensions.yml +++ b/_config/extensions.yml @@ -51,10 +51,6 @@ SilverStripe\CMS\Controllers\CMSMain: - SilverStripe\Subsites\Extensions\HintsCacheKeyExtension - SilverStripe\Subsites\Extensions\SubsiteMenuExtension -SilverStripe\CMS\Controllers\CMSPagesController: - extensions: - - SilverStripe\Subsites\Extensions\SubsiteMenuExtension - SilverStripe\Subsites\Admin\SubsiteAdmin: extensions: - SilverStripe\Subsites\Extensions\SubsiteMenuExtension diff --git a/src/Extensions/LeftAndMainSubsites.php b/src/Extensions/LeftAndMainSubsites.php index 79c259e4..773209a7 100644 --- a/src/Extensions/LeftAndMainSubsites.php +++ b/src/Extensions/LeftAndMainSubsites.php @@ -6,7 +6,7 @@ use SilverStripe\Admin\CMSMenu; use SilverStripe\Admin\CMSProfileController; use SilverStripe\Admin\LeftAndMain; -use SilverStripe\CMS\Controllers\CMSPagesController; +use SilverStripe\CMS\Controllers\CMSMain; use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Controllers\CMSPageEditController; use SilverStripe\Control\Controller; @@ -282,14 +282,6 @@ protected function onBeforeInit() // Catch forced subsite changes that need to cause CMS reloads. if ($request->getVar('SubsiteID') !== null) { - // Clear current page when subsite changes (or is set for the first time) - if ($state->getSubsiteIdWasChanged()) { - // sessionNamespace() is protected - see for info - $override = $this->owner->config()->get('session_namespace'); - $sessionNamespace = $override ? $override : get_class($this->owner); - $session->clear($sessionNamespace . '.currentPage'); - } - // Context: Subsite ID has already been set to the state via InitStateMiddleware // If the user cannot view the current page, redirect to the admin landing section @@ -306,7 +298,7 @@ protected function onBeforeInit() // will show a list of the requested subsite's pages $currentSubsiteId = $request->getVar('SubsiteID'); if ($page && (int) $page->SubsiteID !== (int) $currentSubsiteId) { - return $this->owner->redirect(CMSPagesController::singleton()->Link()); + return $this->owner->redirect(CMSMain::singleton()->Link()); } // Page does belong to the current subsite, so remove the query string parameter and refresh the page @@ -386,7 +378,7 @@ protected function onBeforeInit() return; } - protected function augmentNewSiteTreeItem(&$item) + protected function updateNewItem(&$item) { $request = Controller::curr()->getRequest(); $item->SubsiteID = $request->postVar('SubsiteID') ?: SubsiteState::singleton()->getSubsiteId(); diff --git a/src/Model/Subsite.php b/src/Model/Subsite.php index 8ac132fe..a185a110 100644 --- a/src/Model/Subsite.php +++ b/src/Model/Subsite.php @@ -728,7 +728,8 @@ public function getPageTypeMap() { $pageTypeMap = []; - $pageTypes = SiteTree::page_type_classes(); + $pageTypes = ClassInfo::getValidSubClasses(SiteTree::class); + SiteTree::singleton()->updateAllowedSubClasses($pageTypes); foreach ($pageTypes as $pageType) { $pageTypeMap[$pageType] = singleton($pageType)->i18n_singular_name(); } diff --git a/tests/php/SiteTreeSubsitesTest.php b/tests/php/SiteTreeSubsitesTest.php index adb65115..b0adca56 100644 --- a/tests/php/SiteTreeSubsitesTest.php +++ b/tests/php/SiteTreeSubsitesTest.php @@ -287,7 +287,7 @@ public function testPageTypesBlacklistInCMSMain() Subsite::changeSubsite($s1); $cmsmain = CMSMain::create(); - $hints = json_decode($cmsmain->SiteTreeHints() ?? '', true); + $hints = json_decode($cmsmain->TreeHints() ?? '', true); $classes = $hints['Root']['disallowedChildren']; $this->assertContains(ErrorPage::class, $classes); $this->assertContains(TestClassA::class, $classes); @@ -298,7 +298,7 @@ public function testPageTypesBlacklistInCMSMain() if ($cmsmain->hasMethod('getHintsCache')) { $cmsmain->getHintsCache()->clear(); } - $hints = json_decode($cmsmain->SiteTreeHints() ?? '', true); + $hints = json_decode($cmsmain->TreeHints() ?? '', true); $classes = $hints['Root']['disallowedChildren']; $this->assertNotContains(ErrorPage::class, $classes);