Skip to content

Commit

Permalink
API Update code to reflect changes to LeftAndMain
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Nov 7, 2024
1 parent b6ba2b8 commit dac8c25
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 14 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
1 change: 1 addition & 0 deletions lang/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ en:
db_Protocol: Protocol
has_one_Subsite: Subsite
SilverStripe\Subsites\Pages\SubsitesVirtualPage:
CLASS_DESCRIPTION: 'Displays the content of a page on another subsite'
DESCRIPTION: 'Displays the content of a page on another subsite'
OverrideNote: 'Overrides inherited value from the source'
PLURALNAME: 'Subsites Virtual Pages'
Expand Down
12 changes: 6 additions & 6 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 @@ -280,7 +280,7 @@ protected function onBeforeInit()
// sessionNamespace() is protected - see for info
$override = $this->owner->config()->get('session_namespace');
$sessionNamespace = $override ? $override : get_class($this->owner);
$session->clear($sessionNamespace . '.currentPage');
$session->clear($sessionNamespace . '.currentRecord');
}

// Context: Subsite ID has already been set to the state via InitStateMiddleware
Expand All @@ -293,13 +293,13 @@ protected function onBeforeInit()
$currentController = Controller::curr();
if ($currentController instanceof CMSPageEditController) {
/** @var SiteTree $page */
$page = $currentController->currentPage();
$page = $currentController->currentRecord();

// If the page exists but doesn't belong to the requested subsite, redirect to admin/pages which
// 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 @@ -314,7 +314,7 @@ protected function onBeforeInit()

// Automatically redirect the session to appropriate subsite when requesting a record.
// This is needed to properly initialise the session in situations where someone opens the CMS via a link.
$record = $this->owner->currentPage();
$record = $this->owner->currentRecord();
if ($record
&& isset($record->SubsiteID, $this->owner->urlParams['ID'])
&& is_numeric($record->SubsiteID)
Expand Down Expand Up @@ -379,7 +379,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
2 changes: 1 addition & 1 deletion src/Pages/SubsitesVirtualPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SubsitesVirtualPage extends VirtualPage
{
private static $table_name = 'SubsitesVirtualPage';

private static $description = 'Displays the content of a page on another subsite';
private static $class_description = 'Displays the content of a page on another subsite';

private static $non_virtual_fields = [
'SubsiteID'
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 dac8c25

Please sign in to comment.