Skip to content

Commit

Permalink
fix: make sure menu item is completely deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
wilr authored Sep 8, 2023
1 parent c50fcec commit 0890b85
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/MenuSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 0890b85

Please sign in to comment.