diff --git a/client/dist/js/GridField.js b/client/dist/js/GridField.js index 26d9814..874a6ae 100644 --- a/client/dist/js/GridField.js +++ b/client/dist/js/GridField.js @@ -1 +1 @@ -!function(){"use strict";var e={669:function(e){e.exports=jQuery}},t={};var i=function i(r){var d=t[r];if(void 0!==d)return d.exports;var n=t[r]={exports:{}};return e[r](n,n.exports,i),n.exports}(669);i.entwine("ss",(e=>{e(".ss-gridfield .field .gridfield-dropdown").entwine({onchange(){const e=this.getGridField(),t=e.getState().GridFieldSiteTreeAddNewButton;t.pageType=this.val(),e.setState("GridFieldSiteTreeAddNewButton",t)}})}))}(); \ No newline at end of file +!function(){"use strict";var e={669:function(e){e.exports=jQuery}},t={};var r=function r(i){var d=t[i];if(void 0!==d)return d.exports;var n=t[i]={exports:{}};return e[i](n,n.exports,r),n.exports}(669);r.entwine("ss",(e=>{e(".ss-gridfield .field .gridfield-dropdown").entwine({onchange(){const e=this.getGridField(),t=e.getState().GridFieldSiteTreeAddNewButton;t.recordType=this.val(),e.setState("GridFieldSiteTreeAddNewButton",t)}})}))}(); \ No newline at end of file diff --git a/client/src/js/GridField.js b/client/src/js/GridField.js index 9fcf113..d0f1c1d 100644 --- a/client/src/js/GridField.js +++ b/client/src/js/GridField.js @@ -8,7 +8,7 @@ const gridField = this.getGridField(); const state = gridField.getState().GridFieldSiteTreeAddNewButton; - state.pageType = this.val(); + state.recordType = this.val(); gridField.setState('GridFieldSiteTreeAddNewButton', state); } }); diff --git a/src/Forms/GridFieldSiteTreeAddNewButton.php b/src/Forms/GridFieldSiteTreeAddNewButton.php index f54e97f..9586c32 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) { @@ -66,22 +68,22 @@ public function getHTMLFragments($gridField) { $state = $gridField->State->GridFieldSiteTreeAddNewButton; - $parent = SiteTree::get()->byId(Controller::curr()->currentPageID()); + $parent = SiteTree::get()->byId(Controller::curr()->currentRecordID()); if ($parent) { - $state->currentPageID = $parent->ID; + $state->currentRecordID = $parent->ID; } $children = $this->getAllowedChildren($parent); if (empty($children)) { return array(); } elseif (count($children ?? []) > 1) { - $pageTypes = DropdownField::create('PageType', 'Page Type', $children, $parent->defaultChild()); + $pageTypes = DropdownField::create('RecordType', 'Page Type', $children, $parent->defaultChild()); $pageTypes ->setFieldHolderTemplate(__CLASS__ . '_holder') ->addExtraClass('gridfield-dropdown no-change-track'); - $state->pageType = $parent->defaultChild(); + $state->RecordType = $parent->defaultChild(); if (!$this->buttonName) { $this->buttonName = _t( @@ -92,9 +94,9 @@ public function getHTMLFragments($gridField) } } else { $keys = array_keys($children ?? []); - $pageTypes = HiddenField::create('PageType', 'Page Type', $keys[0]); + $pageTypes = HiddenField::create('RecordType', 'Page Type', $keys[0]); - $state->pageType = $keys[0]; + $state->recordType = $keys[0]; if (!$this->buttonName) { $this->buttonName = _t( @@ -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 @@ -147,20 +149,20 @@ public function handleAction(GridField $gridField, $actionName, $arguments, $dat $tmpData = $tmpData['GridFieldSiteTreeAddNewButton']; $data = array( - 'ParentID' => $tmpData['currentPageID'], - 'PageType' => $tmpData['pageType'] + 'ParentID' => $tmpData['currentRecordID'], + 'RecordType' => $tmpData['recordType'] ); - $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; diff --git a/src/Forms/GridFieldSiteTreeEditButton.php b/src/Forms/GridFieldSiteTreeEditButton.php index c11c608..f6e0754 100644 --- a/src/Forms/GridFieldSiteTreeEditButton.php +++ b/src/Forms/GridFieldSiteTreeEditButton.php @@ -28,7 +28,7 @@ public function getColumnContent($gridField, $record, $columnName) // which can make the form readonly if no edit permissions are available. $data = ArrayData::create([ - 'Link' => $record->CMSEditLink(), + 'Link' => $record->getCMSEditLink(), 'ExtraClass' => $this->getExtraClass(), ]); diff --git a/src/Model/Lumberjack.php b/src/Model/Lumberjack.php index af44f75..0553604 100644 --- a/src/Model/Lumberjack.php +++ b/src/Model/Lumberjack.php @@ -28,7 +28,7 @@ * * @author Michael Strong * - * @extends SiteTreeExtension + * @extends Extension */ class Lumberjack extends Extension { diff --git a/yarn.lock b/yarn.lock index 16cbd7a..2b5ebec 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2172,9 +2172,9 @@ cosmiconfig@^9.0.0: parse-json "^5.2.0" cross-spawn@^7.0.2, cross-spawn@^7.0.3: - version "7.0.5" - resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.5.tgz#910aac880ff5243da96b728bc6521a5f6c2f2f82" - integrity sha512-ZVJrKKYunU38/76t0RMOulHOnUcbU9GbpWKAOZ0mhjr7CX6FVrH+4FrAapSOekrgFQ3f/8gwMEuIft0aKq6Hug== + version "7.0.6" + resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.6.tgz#8a58fe78f00dcd70c370451759dfbfaf03e8ee9f" + integrity sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA== dependencies: path-key "^3.1.0" shebang-command "^2.0.0"