GridField Unlink Action for Page

Hi Everyone

silverstripe 4.X,

By Default $many_many field with DataObject displays Edit and Unlink in GridMenu.

I have gridField in page with $many_many to other pages, In Grid Action menu it is showing Edit and ARCHIVE

Is there any way I can enable Unlink for the pages as well in gried action menu.

Thanks

private static $many_many = [
'Categories'=>NewsCategory::class // NewsCategory extends Page
];

// public function getCMSFields()

$category_config = GridFieldConfig_RelationEditor::create();
$category = ToggleCompositeField::create(
    'CategoriesSection',
    $this->fieldLabel('Categories'),
    array(
        new GridField('Categories','Categories',$this->Categories(),$category_config)
    )
);

grid-field

Hi,

TLDR; just add below after the line: $category_config = GridFieldConfig_RelationEditor::create(); to fix the problem:

$category_config->removeComponentsByType(‘SilverStripe\Versioned\GridFieldArchiveAction’);

example:

$config =   GridFieldConfig_RelationEditor::create();
$config->removeComponentsByType('SilverStripe\Versioned\GridFieldArchiveAction');
$delete = $config->getComponentByType(GridFieldDeleteAction::class);
$delete->setRemoveRelation(true);

Short story long (below is my guessing):
At some point (sorry, just don’t have time to look where exactly the point is), when SilverStripe injects “GridFieldArchiveAction” to Gridfield, they might mess up SilverStripe\Forms\GridField\GridFieldArchiveAction with SilverStripe\Versioned\GridFieldArchiveAction :confused:

Hope this helps

Cheers
Leo

1 Like

Thanks a lot, that was really helpful

$config = GridFieldConfig_RelationEditor::create();
$config->removeComponentsByType(‘SilverStripe\Versioned\GridFieldArchiveAction’);
$config->addComponent(new GridFieldDeleteAction(true));