Reputation: 747
In Silverstripe 3.3.1 GridFieldExportButton seems impossible to override. In this case I am using userforms and I need to take control of functions in GridFieldExportButton like generateExportFileData() in order to alter certain behaviours like using field labels as field names in the csv and including
tags.
I have tried extending directly
class SubmissionExportButton extends GridFieldExportButton
Through _config.php
Object::add_extension('GridFieldExportButton', 'SubmissionExportButton');
class SubmissionExportButton extends Extension{}
and Through Injector.
class SubmissionExportButton extends GridFieldExportButton{}
Injector:
GridFieldExportButton:
class: SubmissionExportButton
I have even attempted to completely replace the class and extend UserDefinedForm but his had some unexpected results. Better to simply take control of the class in question, but what is the right procedure?
Upvotes: 2
Views: 142
Reputation: 143
Injector should be perfectly suited for this, so just to double check your process:
~/mysite/_config/config.yml
Injector:
GridFieldExportButton:
class: SubmissionExportButton
~/mysite/code/SubmissionExportButton.php
class SubmissionExportButton extends GridFieldExportButton
{
public function generateExportFileData($gridField)
{
// override here, retain return types!
}
// etc...
}
Then:
run ~/dev/build/?flush
run ~/admin/pages/?flush
I have sometimes had issues that the CMS cache does not clear in a manner consistent with the front-end flush, but I've definitely had to run it to get certain tweaks working in the past. I've even had to flush the CMS multiple times, but that's generally when I've reached $utter_frustration_point
or 3am in the morning :P
I also checked silverstripe/silverstripe-userforms
just to be sure they are not already overriding GridFieldExportButton
- seems not, so good luck, I hope this helps :)
Upvotes: 0
Reputation: 3318
I would copy the approach taken within https://github.com/axyr/silverstripe-phpexcel to create a new component and unregister the default one and register this instead.
Upvotes: 1