From d8b8b4f6dc11a16b8dc4fc512e96d58c006f50f4 Mon Sep 17 00:00:00 2001 From: Pat Dunlavey Date: Sun, 27 May 2018 08:53:14 -0400 Subject: [PATCH] ISLANDORA-1748 -- add hook_islandora_datastream_filename_alter(). (#706) * ISLANDORA-1748 -- add hook_datastream_filename_alter(). Co-authored-by: Diego Pino Navarro --- includes/datastream.inc | 4 ++++ islandora.api.php | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/includes/datastream.inc b/includes/datastream.inc index 8584e53e..41432333 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -63,6 +63,10 @@ function islandora_view_datastream(AbstractDatastream $datastream, $download = F if ($duplicate_extension_position === FALSE) { $filename .= $extension; } + + // Allow other modules to modify or replace the filename. + drupal_alter('islandora_datastream_filename', $filename, $datastream); + header("Content-Disposition: attachment; filename=\"$filename\""); } diff --git a/islandora.api.php b/islandora.api.php index e553a894..c5de95e1 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -945,3 +945,24 @@ function callback_islandora_breadcrumbs_backends(AbstractObject $object) { // Do something to get an array of breadcrumb links for $object, root first. return array($root_link, $collection_link, $object_link); } + +/** + * Permit modules to alter the filename of a downloaded datastream. + * + * @param string $filename + * The filename being created. + * + * @param AbstractDatastream $datastream + * The datastream object being downloaded. + */ +function hook_islandora_datastream_filename_alter(&$filename, AbstractDatastream $datastream) { + + // Example taken from islandora_datastream_filenamer. + $pattern = variable_get('islandora_ds_download_filename_pattern', FALSE); + if ($pattern) { + $filename = token_replace($pattern, + array('datastream' => $datastream), + array('clear' => TRUE) + ); + } +}