Skip to content

Commit

Permalink
Merge branch '4.0' into 4
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Dec 12, 2024
2 parents 52f2b69 + 0d0bb6e commit 9eb376b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/GridField.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/src/js/GridField.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down
34 changes: 18 additions & 16 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 All @@ -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(
Expand All @@ -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(
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 @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/GridFieldSiteTreeEditButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
]);

Expand Down
2 changes: 1 addition & 1 deletion src/Model/Lumberjack.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*
* @author Michael Strong <[email protected]>
*
* @extends SiteTreeExtension<SiteTree&static>
* @extends Extension<SiteTree&static>
*/
class Lumberjack extends Extension
{
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 9eb376b

Please sign in to comment.