From 368118be4a8115d6faae956195c5ee9634ad9b0a Mon Sep 17 00:00:00 2001 From: Andrew Mc Cormack Date: Wed, 6 Feb 2019 11:48:49 +0000 Subject: [PATCH] remove custom delete action and orderable rows classes --- src/Action/GridFieldVersionedDeleteAction.php | 41 ------------------ .../GridFieldVersionedOrderableRows.php | 43 ------------------- src/Extension/BlockPageExtension.php | 22 +++------- 3 files changed, 6 insertions(+), 100 deletions(-) delete mode 100644 src/Action/GridFieldVersionedDeleteAction.php delete mode 100644 src/Action/GridFieldVersionedOrderableRows.php diff --git a/src/Action/GridFieldVersionedDeleteAction.php b/src/Action/GridFieldVersionedDeleteAction.php deleted file mode 100644 index acb925a..0000000 --- a/src/Action/GridFieldVersionedDeleteAction.php +++ /dev/null @@ -1,41 +0,0 @@ - - **/ -namespace CyberDuck\BlockPage\Action; - -use SilverStripe\Forms\GridField\GridField; -use SilverStripe\Forms\GridField\GridFieldDeleteAction; -use SilverStripe\Versioned\Versioned; - -class GridFieldVersionedDeleteAction extends GridFieldDeleteAction -{ - public function handleAction(GridField $gridField, $actionName, $arguments, $data) - { - // remove from live - if ($actionName == 'deleterecord' || $actionName == 'unlinkrelation') { - $item = $gridField->getList()->byID($arguments['RecordID']); - if (!$item) { - return; - } - if ($actionName == 'unlinkrelation') { - if (!$item->canEdit()) { - throw new ValidationException( - _t(__CLASS__.'.EditPermissionsFailure', "No permission to unlink record") - ); - } - //$item->PageContentBlock->deleteFromStage(Versioned::LIVE); - } - } - // remove from stage - parent::handleAction($gridField, $actionName, $arguments, $data); - } -} \ No newline at end of file diff --git a/src/Action/GridFieldVersionedOrderableRows.php b/src/Action/GridFieldVersionedOrderableRows.php deleted file mode 100644 index ebf5bae..0000000 --- a/src/Action/GridFieldVersionedOrderableRows.php +++ /dev/null @@ -1,43 +0,0 @@ -getSortField(); - - $map = $list->map('ID', $sortField); - if ($map instanceof Map) { - $map = $map->toArray(); - } - - $class = $list->dataClass(); - $isVersioned = $class::has_extension(Versioned::class); - - if($isVersioned && $list instanceof ManyManyList) { - $sortTable = $this->getSortTable($list); - foreach ($sortedIDs as $sortValue => $id) { - if ($map[$id] != $sortValue) { - $sql = sprintf( - 'UPDATE "%s" SET "%s" = %d WHERE %s', - $sortTable, - $sortField, - $sortValue, - $this->getSortTableClauseForIds($list, $id) - ); - DB::query($sql); - } - } - } - } -} \ No newline at end of file diff --git a/src/Extension/BlockPageExtension.php b/src/Extension/BlockPageExtension.php index cd90d7f..8ebd6f6 100644 --- a/src/Extension/BlockPageExtension.php +++ b/src/Extension/BlockPageExtension.php @@ -2,28 +2,21 @@ namespace CyberDuck\BlockPage\Extension; -use Page; use CyberDuck\BlockPage\Action\GridFieldVersionedContentBlockItemRequest; -use CyberDuck\BlockPage\Action\GridFieldVersionedDeleteAction; -use CyberDuck\BlockPage\Action\GridFieldVersionedOrderableRows; use CyberDuck\BlockPage\Model\ContentBlock; -use CyberDuck\BlockPage\Model\PageContentBlock; use SilverStripe\Control\Controller; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\LiteralField; use SilverStripe\Forms\GridField\GridField; use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor; -use SilverStripe\Forms\GridField\GridFieldDeleteAction; use SilverStripe\Forms\GridField\GridFieldDetailForm; use SilverStripe\Forms\GridField\GridFieldPageCount; use SilverStripe\Forms\GridField\GridFieldPaginator; -use SilverStripe\Forms\GridField\GridFieldVersionedState; use SilverStripe\ORM\DataExtension; -use SilverStripe\ORM\DataObject; use Symbiote\GridFieldExtensions\GridFieldOrderableRows; class BlockPageExtension extends DataExtension -{ +{ private static $db = []; private static $many_many = [ @@ -40,18 +33,15 @@ class BlockPageExtension extends DataExtension 'ContentBlocks' ]; - public function updateCMSFields(FieldList $fields) - { - if($this->owner->ID > 0) { + public function updateCMSFields(FieldList $fields) + { + if ($this->owner->ID > 0) { $editor = GridFieldConfig_RelationEditor::create(); $grid = new GridField('ContentBlocks', 'Content Blocks', $this->owner->ContentBlocks(), $editor); $grid->getConfig() - ->removeComponentsByType(GridFieldDeleteAction::class) ->removeComponentsByType(GridFieldPageCount::class) ->removeComponentsByType(GridFieldPaginator::class) - ->addComponent(new GridFieldVersionedState(['Title'])) - ->addComponent(new GridFieldVersionedOrderableRows('SortBlock')) - ->addComponent(new GridFieldVersionedDeleteAction(true)) + ->addComponent(new GridFieldOrderableRows('SortBlock')) ->getComponentByType(GridFieldDetailForm::class) ->setItemRequestClass(GridFieldVersionedContentBlockItemRequest::class); @@ -66,4 +56,4 @@ public function updateCMSFields(FieldList $fields) $fields->addFieldToTab('Root.ContentBlocks', LiteralField::create(false, 'Please save this block to start adding items

')); } } -} \ No newline at end of file +}