I'm writing a plugin that gathers up all the assets from an entry and saves it out as a zip (along with a JSON file with information from the entry). Any advice regarding a better method is appreciated, but right now I add the code in on('entries.saveEntry'), like so:
craft()->on('entries.saveEntry', function(Event $event) {
$entry = $event->params['entry'];
$outputArray = array();
/*
business logic filling variables removed for the sake of brevity
*/
if (($entry['sectionId'] == 3) && ($entry['buildPage'] == 1)) {
file_put_contents(getcwd()."/build/videos.json", json_encode($outputArray));
$assetGroup[] = getcwd()."/build/videos.json";
$zipfile = craft()->buildPage->create_zip($assetGroup, $entry['uri'], getcwd()."/build/");
$filename = substr($zipfile,strrpos($zipfile,'/')+1);
if (file_exists($zipfile)) {
craft()->request->sendFile($filename, file_get_contents( $zipfile ), array('forceDownload' => true), false);
}
}
});
Everything works, except that my sendFile call prevents the user from being returned to the Entries page (or stating a new entry, etc.), if that was their intent. Is it possible to capture where they were headed before I stopped them, so that I can send them on their way? Or is that not possible the way I have things written?