From 39819bc6be2337b6dcc8870a6fa7fed87d4c5aea Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Thu, 7 Nov 2024 16:34:22 +1300 Subject: [PATCH] ENH Update code to reflect changes in silverstripe/cms --- src/Forms/GridFieldSiteTreeAddNewButton.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Forms/GridFieldSiteTreeAddNewButton.php b/src/Forms/GridFieldSiteTreeAddNewButton.php index 7007f38..543641b 100644 --- a/src/Forms/GridFieldSiteTreeAddNewButton.php +++ b/src/Forms/GridFieldSiteTreeAddNewButton.php @@ -2,10 +2,11 @@ namespace SilverStripe\Lumberjack\Forms; -use SilverStripe\CMS\Controllers\CMSPageAddController; +use SilverStripe\CMS\Controllers\CMSMain; use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Control\Controller; use SilverStripe\Control\HTTPResponse; +use SilverStripe\Core\ClassInfo; use SilverStripe\Core\Config\Config; use SilverStripe\Core\Injector\Injector; use SilverStripe\Forms\DropdownField; @@ -42,7 +43,8 @@ public function getAllowedChildren(SiteTree $parent = null) return array(); } - $nonHiddenPageTypes = SiteTree::page_type_classes(); + $nonHiddenPageTypes = ClassInfo::getValidSubClasses(SiteTree::class); + SiteTree::singleton()->updateAllowedSubClasses($nonHiddenPageTypes); $allowedChildren = $parent->allowedChildren(); $children = array(); foreach ($allowedChildren as $class) { @@ -131,7 +133,7 @@ public function getActions($gridField) } /** - * Handles the add action, but only acts as a wrapper for {@link CMSPageAddController::doAdd()} + * Handles the add action, but only acts as a wrapper for CMSMain * * @param GridField $gridField * @param string $actionName @@ -151,16 +153,16 @@ public function handleAction(GridField $gridField, $actionName, $arguments, $dat 'PageType' => $tmpData['pageType'] ); - $controller = Injector::inst()->create(CMSPageAddController::class); + $controller = Injector::inst()->create(CMSMain::class); + $form = $controller->AddForm(); - // pass current request to newly created controller + // pass current request down in case either of these needs it $request = Controller::curr()->getRequest(); $controller->setRequest($request); + $form->getRequestHandler()->setRequest($request); - $form = $controller->AddForm(); $form->loadDataFrom($data); - - return $controller->doAdd($data, $form); + return $form->doAdd($data, $form); } return null;