Remove "Unlink" option from Gridfields

Silverstripe Version: 4.5

Question: Remove “Unlink” option from Gridfields

Having trouble removing the “Unlink” option from a has_many field in the grid field.

use SilverStripe\Versioned\GridFieldUnlinkAction;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig;
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor;


public function getCMSFields()
    $dataMapsGrid = GridField::create('DataMaps', 'Data Maps', $this->DataMaps(), GridFieldConfig_RelationEditor::create());

    // Was hoping this would remove the "Unlink" action
    // Removes "Link Existing" action

    $fields = new FieldList(
      new TextField('Title', 'Title', null, 128),
    $this->extend('updateCMSFields', $fields);
    return $fields;

By the look of it, you might be better off using a different configuration to start with. Instead of the GridFieldConfig_RelationEditor, you might try a GridFieldConfig_RecordEditor instead.

1 Like