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());
$dataMapsGrid->getConfig()
// Was hoping this would remove the "Unlink" action
->removeComponentsByType(GridFieldUnlinkAction::class)
// Removes "Link Existing" action
->removeComponentsByType(GridFieldAddExistingAutocompleter::class);
$fields = new FieldList(
new TextField('Title', 'Title', null, 128),
$dataMapsGrid
);
$this->extend('updateCMSFields', $fields);
return $fields;
}