diff --git a/includes/datastream.inc b/includes/datastream.inc index 8584e53e..d1e09060 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -63,6 +63,11 @@ 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('datastream_filename', $filename, $datastream); + + header("Content-Disposition: attachment; filename=\"$filename\""); } diff --git a/islandora.api.php b/islandora.api.php index e553a894..36d8c25a 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -945,3 +945,21 @@ 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 + * @param AbstractDatastream $datastream + */ +function hook_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) + ); + } +}