From 0890b8535543649d3f3f076c2d7e4da60018bd15 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Fri, 8 Sep 2023 15:22:08 +1200 Subject: [PATCH] fix: make sure menu item is completely deleted --- src/MenuSet.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/MenuSet.php b/src/MenuSet.php index 47a80d6..82ae8c7 100644 --- a/src/MenuSet.php +++ b/src/MenuSet.php @@ -6,6 +6,7 @@ use SilverStripe\Forms\GridField\GridField; use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter; use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor; +use SilverStripe\Forms\GridField\GridFieldDeleteAction; use SilverStripe\Forms\TabSet; use SilverStripe\Forms\TextareaField; use SilverStripe\Forms\TextField; @@ -218,20 +219,25 @@ public function createDefaultMenuSets() public function getCMSFields(): FieldList { $fields = FieldList::create(TabSet::create('Root')); - if ($this->ID != null) { $fields->removeByName('Name'); - + $config = GridFieldConfig_RelationEditor::create(); $fields->addFieldToTab( 'Root.Main', new GridField( 'MenuItems', '', $this->MenuItems(), - $config = GridFieldConfig_RelationEditor::create() + $config ) ); + $remove = $config->getComponentByType(GridFieldDeleteAction::class); + + if ($remove) { + $remove->setRemoveRelation(false); + } + $config->addComponent(new GridFieldOrderableRows('Sort')); $config->removeComponentsByType(GridFieldAddExistingAutocompleter::class); $fields->addFieldToTab(