SilverStripe删除CSV导出按钮

时间:2016-07-14 12:22:22

标签: silverstripe

我尝试删除GridFieldModelAdmin顶部的导出为CSV 按钮。

我似乎无法找到创建按钮的类(GridFieldExportButton对吗?)。我猜测有一个函数用按钮/"动作"填充GridField。我不熟悉。

1 个答案:

答案 0 :(得分:7)

删除脚手架的GridField以获取关系......

class MyDataObject extends DataObject {

    ...

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

    ...

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

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

        return $fields;
    }

    ...

}

如果你正在创建GridField,那么只需在创建字段时添加它......

$gridField->getConfig()->removeComponentsByType('GridFieldExportButton'); 

如果您正在寻找不在数据对象编辑表单中且实际上是...的网格字段

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('GridFieldExportButton');
        }
        return $form;
    }

    ...
}

将model_importers设置为空将执行相反操作并删除导入...

class MyAdmin extends ModelAdmin {

    ...

    static $model_importers = array();

    ...
}