Silverstripe Version: 4.10.8
Question: What should I add to handleAction to create and download a file in a GridField?
I would like to create a GridField custom action that downloads a markdown text file created on-the-fly from a DataObject. I feel like I should be able to do something like this:
public function handleAction(GridField $gridField, $actionName, $arguments, $data)
{
if ($actionName == 'dofiledownloadaction') {
// get item
$item = $gridField->getList()->byID($arguments['RecordID']);
// update last downloaded timestamp
$item->LastDownloaded = DBDatetime::now()->getTimestamp();
$item->write();
// send file for download
$fileData = $item->getMarkdown(); // returns string of markdown from item
$filename = "download.md"
return HTTPRequest::send_file($fileData, $fileName, 'text/markdown');
}
}
I’ve exhausted all places I can look to see how to approach something like this