diff --git a/includes/datastream.inc b/includes/datastream.inc index 902d5670..e8aa2fbd 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -84,9 +84,12 @@ function islandora_datastream_get_url(AbstractDatastream $datastream, $type = 'd * The datastream to generated the url to. */ function islandora_datastream_get_delete_link(AbstractDatastream $datastream) { - $datastreams = module_invoke_all('islandora_undeletable_datastreams', $datastream->parent->models); - $can_delete = !in_array($datastream->id, $datastreams) && islandora_datastream_access(FEDORA_PURGE, $datastream); - return $can_delete ? l(t('delete'), "islandora/object/{$datastream->parent->id}/datastream/{$datastream->id}/delete") : ''; + $message = islandora_deprecated('7.x-1.2', 'Use the "islandora_datastream_delete_link" theme implementation.'); + trigger_error($message, E_USER_DEPRECATED); + + return theme('islandora_datastream_delete_link', array( + 'datastream' => $datastream, + )); } /** @@ -96,9 +99,12 @@ function islandora_datastream_get_delete_link(AbstractDatastream $datastream) { * The datastream to generated the url to. */ function islandora_datastream_edit_get_link(AbstractDatastream $datastream) { - $edit_registry = module_invoke_all('islandora_edit_datastream_registry', $datastream->parent, $datastream); - $can_edit = count($edit_registry) > 0 && islandora_datastream_access(FEDORA_METADATA_EDIT, $datastream); - return $can_edit ? l(t('edit'), "islandora/object/{$datastream->parent->id}/datastream/{$datastream->id}/edit") : ''; + $message = islandora_deprecated('7.x-1.2', 'Use the "islandora_datastream_edit_link" theme implementation.'); + trigger_error($message, E_USER_DEPRECATED); + + return theme('islandora_datastream_edit_link', array( + 'datastream' => $datastream, + )); } /** @@ -156,10 +162,12 @@ function islandora_edit_datastream_registry_render(array $edit_registry) { * user is not allowed to see the given datastream. */ function islandora_datastream_get_download_link(AbstractDatastream $datastream) { - $label = t('download'); - return islandora_datastream_access(FEDORA_VIEW_OBJECTS, $datastream) ? - l($label, islandora_datastream_get_url($datastream, 'download')) : - ''; + $message = islandora_deprecated('7.x-1.2', 'Use the "islandora_datastream_download_link" theme implementation.'); + trigger_error($message, E_USER_DEPRECATED); + + return theme('islandora_datastream_download_link', array( + 'datastream' => $datastream, + )); } /** @@ -173,8 +181,10 @@ function islandora_datastream_get_download_link(AbstractDatastream $datastream) * datastream ID if the user is not allowed to see the given datastream. */ function islandora_datastream_get_view_link(AbstractDatastream $datastream) { - $label = check_plain($datastream->id); - return islandora_datastream_access(FEDORA_VIEW_OBJECTS, $datastream) ? - l($label, islandora_datastream_get_url($datastream, 'view')) : - $label; + $message = islandora_deprecated('7.x-1.2', 'Use the "islandora_datastream_view_link" theme implementation.'); + trigger_error($message, E_USER_DEPRECATED); + + return theme('islandora_datastream_view_link', array( + 'datastream' => $datastream, + )); } diff --git a/islandora.module b/islandora.module index 3c7d9419..baa1460c 100644 --- a/islandora.module +++ b/islandora.module @@ -322,6 +322,22 @@ function islandora_theme() { 'template' => 'theme/islandora-objects-list', 'variables' => array('objects' => NULL), ), + 'islandora_datastream_edit_link' => array( + 'file' => 'theme/theme.inc', + 'variables' => array('datastream' => NULL), + ), + 'islandora_datastream_delete_link' => array( + 'file' => 'theme/theme.inc', + 'variables' => array('datastream' => NULL), + ), + 'islandora_datastream_view_link' => array( + 'file' => 'theme/theme.inc', + 'variables' => array('datastream' => NULL), + ), + 'islandora_datastream_download_link' => array( + 'file' => 'theme/theme.inc', + 'variables' => array('datastream' => NULL), + ), ); } diff --git a/theme/theme.inc b/theme/theme.inc index ce6f2659..cf048745 100644 --- a/theme/theme.inc +++ b/theme/theme.inc @@ -29,7 +29,9 @@ function islandora_preprocess_islandora_default_edit(array &$variables) { $rows[] = array( array( 'class' => 'datastream-id', - 'data' => islandora_datastream_get_view_link($ds), + 'data' => theme('islandora_datastream_view_link', array( + 'datastream' => $ds, + )), ), array( 'class' => 'datastream-label', @@ -49,15 +51,21 @@ function islandora_preprocess_islandora_default_edit(array &$variables) { ), array( 'class' => 'datastream-download', - 'data' => islandora_datastream_get_download_link($ds), + 'data' => theme('islandora_datastream_download_link', array( + 'datastream' => $ds, + )), ), array( 'class' => 'datstream-edit', - 'data' => islandora_datastream_edit_get_link($ds), + 'data' => theme('islandora_datastream_edit_link', array( + 'datastream' => $ds, + )), ), array( 'class' => 'datastream-delete', - 'data' => islandora_datastream_get_delete_link($ds), + 'data' => theme('islandora_datastream_delete_link', array( + 'datastream' => $ds, + )), ), ); } @@ -224,3 +232,75 @@ function islandora_preprocess_islandora_objects(array &$variables) { $module_path = drupal_get_path('module', 'islandora'); drupal_add_css("$module_path/css/islandora.objects.css"); } + +/** + * Renders a link to allow downloading of a datatream. + * + * @param array $vars + * An array containing: + * - datastream: An AbstractDatastream for which to generate a download link. + */ +function theme_islandora_datastream_download_link(array $vars) { + $datastream = $vars['datastream']; + module_load_include('inc', 'islandora', 'includes/utilities'); + + $label = t('download'); + return islandora_datastream_access(FEDORA_VIEW_OBJECTS, $datastream) ? + l($label, islandora_datastream_get_url($datastream, 'download')) : + ''; +} + +/** + * Renders a link to allow viewing of a datatream. + * + * @param array $vars + * An array containing: + * - datastream: An AbstractDatastream for which to generate a view link. + */ +function theme_islandora_datastream_view_link(array $vars) { + $datastream = $vars['datastream']; + module_load_include('inc', 'islandora', 'includes/utilities'); + + $label = check_plain($datastream->label); + return islandora_datastream_access(FEDORA_VIEW_OBJECTS, $datastream) ? + l($label, islandora_datastream_get_url($datastream, 'view')) : + $label; +} + +/** + * Renders a link to allow deleting of a datatream. + * + * @param array $vars + * An array containing: + * - datastream: An AbstractDatastream for which to generate a delete link. + */ +function theme_islandora_datastream_delete_link(array $vars) { + $datastream = $vars['datastream']; + + $datastreams = module_invoke_all('islandora_undeletable_datastreams', $datastream->parent->models); + + $can_delete = !in_array($datastream->id, $datastreams) && islandora_datastream_access(FEDORA_PURGE, $datastream); + + return $can_delete ? + l(t('delete'), "islandora/object/{$datastream->parent->id}/datastream/{$datastream->id}/delete") : + ''; +} + +/** + * Renders a link to allow editing of a datatream. + * + * @param array $vars + * An array containing: + * - datastream: An AbstractDatastream for which to generate a edit link. + */ +function theme_islandora_datastream_edit_link(array $vars) { + $datastream = $vars['datastream']; + + $edit_registry = module_invoke_all('islandora_edit_datastream_registry', $datastream->parent, $datastream); + + $can_edit = count($edit_registry) > 0 && islandora_datastream_access(FEDORA_METADATA_EDIT, $datastream); + + return $can_edit ? + l(t('edit'), "islandora/object/{$datastream->parent->id}/datastream/{$datastream->id}/edit") : + ''; +}