Skip to content

Commit

Permalink
API Update code to reflect changes to LeftAndMain (#618)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored Dec 12, 2024
1 parent 3611352 commit 41bf02c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 22 deletions.
4 changes: 0 additions & 4 deletions _config/extensions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 5 additions & 15 deletions src/Extensions/LeftAndMainSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -274,22 +274,12 @@ public function alternateAccessCheck(?Member $member = null)
protected function onBeforeInit()
{
$request = Controller::curr()->getRequest();
$session = $request->getSession();

$state = SubsiteState::singleton();

// FIRST, check if we need to change subsites due to the URL.

// 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
Expand All @@ -306,7 +296,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
Expand All @@ -328,11 +318,11 @@ protected function onBeforeInit()
&& $this->shouldChangeSubsite(
get_class($this->owner),
$record->SubsiteID,
SubsiteState::singleton()->getSubsiteId()
$state->getSubsiteId()
)
) {
// Update current subsite
$canViewElsewhere = SubsiteState::singleton()->withState(function ($newState) use ($record) {
$canViewElsewhere = $state->withState(function ($newState) use ($record) {
$newState->setSubsiteId($record->SubsiteID);

return (bool) $this->owner->canView(Security::getCurrentUser());
Expand Down Expand Up @@ -386,7 +376,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();
Expand Down
3 changes: 2 additions & 1 deletion src/Model/Subsite.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/php/SiteTreeSubsitesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 41bf02c

Please sign in to comment.