Skip to content

Commit

Permalink
ENH Update code to reflect changes in silverstripe/cms
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Nov 27, 2024
1 parent a114fd2 commit 39819bc
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/Forms/GridFieldSiteTreeAddNewButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit 39819bc

Please sign in to comment.