Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SilverStripe remove CSV Export button

Tags:

silverstripe

I'm trying to remove the Export to CSV button in the top of a GridField in ModelAdmin.

I can't seem to find the class that creates the button (GridFieldExportButton right?). I'm guessing there is a function that populates the GridField with buttons / "actions" which I'm not familiar with.

like image 714
Semicolon Avatar asked Feb 06 '23 13:02

Semicolon


1 Answers

To remove the scaffolded GridField for relationships...

class MyDataObject extends DataObject {

    ...

    private static $has_many= array(
        'OtherDataObjects' => 'OtherDataObject'
    );

    ...

    function getCMSFields() {
        $fields = parent::getCMSFields();

        if($grid = $fields->dataFieldByName('OtherDataObjects'))
            $grid->getConfig()
                ->removeComponentsByType('SilverStripe\Forms\GridField\GridFieldExportButton');

        return $fields;
    }

    ...

}

If you are making the GridField then just add this when you create the field...

$gridField->getConfig()->removeComponentsByType('SilverStripe\Forms\GridField\GridFieldExportButton'); 

If you are looking for a gridfield that isn't within a data object edit form and is actually...

class MyAdmin extends ModelAdmin {

    ...

    function getEditForm($id = null, $fields = null) {
        $form = parent::getEditForm($id, $fields);

        if($this->modelClass == 'MyDataObjectName') {
            $form->Fields()
                ->fieldByName($this->sanitiseClassName($this->modelClass))
                ->getConfig()
                ->removeComponentsByType('SilverStripe\Forms\GridField\GridFieldExportButton');
        }
        return $form;
    }

    ...
}

Setting model_importers to empty will do the reverse and remove the import ...

class MyAdmin extends ModelAdmin {

    ...

    static $model_importers = array();

    ...
}
like image 123
Barry Avatar answered Apr 28 '23 05:04

Barry