From 47dfae24c03a58cbc3e55e33a866d29a81aa1e62 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Tue, 27 Nov 2012 14:29:57 +0000 Subject: [PATCH] Changes needed for form builder. --- includes/datastream.inc | 84 +++++++++++++++++++++------------------ islandora.module | 6 +-- theme/islandora.theme.inc | 2 +- 3 files changed, 50 insertions(+), 42 deletions(-) diff --git a/includes/datastream.inc b/includes/datastream.inc index 1c67f9ac..c6cb2780 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -85,52 +85,60 @@ function islandora_datastream_get_url(FedoraDatastream $datastream, $type = 'dow */ function islandora_datastream_get_delete_link(FedoraDatastream $datastream) { $datastreams = module_invoke_all('islandora_undeletable_datastreams', $datastream->parent->models); - if (in_array($datastream->id, $datastreams)) { - return ''; - } - else { - return l(t('delete'), 'islandora/object/' . $datastream->parent->id . '/datastream/' . $datastream->id . '/delete'); - } + $can_delete = !in_array($datastream->id, $datastreams); + return $can_delete ? l(t('delete'), "islandora/object/{$datastream->parent->id}/datastream/{$datastream->id}/delete") : ''; } - -function islandora_datastream_edit_get_link($object, $ds_id) { - $edit_registry = module_invoke_all('islandora_edit_datastream_registry', $object, $ds_id); - if (count($edit_registry) > 0 && user_access(FEDORA_METADATA_EDIT)) { - return l(t('edit'), 'islandora/object/' . $object->id . '/datastream/' . $ds_id . '/edit'); - } - else { - return ''; - } +/** + * Gets the edit link. + * + * @param FedoraDatastream $datastream + * The datastream to generated the url to. + */ +function islandora_datastream_edit_get_link(FedoraDatastream $datastream) { + $edit_registry = module_invoke_all('islandora_edit_datastream_registry', $datastream->parent, $datastream); + $can_edit = count($edit_registry) > 0 && user_access(FEDORA_METADATA_EDIT); + return $can_edit ? l(t('edit'), "islandora/object/{$datastream->parent->id}/datastream/{$datastream->id}/edit") : ''; } -function islandora_edit_datastream($object, $ds_id) { - $edit_registry = module_invoke_all('islandora_edit_datastream_registry', $object, $ds_id); +/** + * Display the edit datastream page. + * + * @param FedoraDatastream $datastream + * The datastream to edit. + */ +function islandora_edit_datastream(FedoraDatastream $datastream) { + $edit_registry = module_invoke_all('islandora_edit_datastream_registry', $datastream->parent, $datastream); $edit_count = count($edit_registry); - - if ($edit_count == 0) { - // No edit implementations. - drupal_set_message(t('There are no edit methods specified for this datastream.')); - drupal_goto('islandora/object/' . $object->id . '/manage/datastreams'); - } - elseif ($edit_count == 1) { - // One registry implementation, go there - drupal_goto($edit_registry[0]['url']); - } - else { - // Multiple edit routes registered - return islandora_edit_datastream_registry_render($edit_registry); + switch ($edit_count) { + case 0: + // No edit implementations. + drupal_set_message(t('There are no edit methods specified for this datastream.')); + drupal_goto("islandora/object/{$object->id}/manage/datastreams"); + break; + case 1: + // One registry implementation, go there + drupal_goto($edit_registry[0]['url']); + break; + default: + // Multiple edit routes registered + return islandora_edit_datastream_registry_render($edit_registry); } } -// @TODO: theme / preprocess -function islandora_edit_datastream_registry_render($edit_registry) { - $output = array( +/** + * Displays links to all the edit datastream registry items. + * + * @param array $edit_registry + * A list of 'islandora_edit_datastream_registry' values. + */ +function islandora_edit_datastream_registry_render(array $edit_registry) { + $markup = ''; + foreach ($edit_registry as $edit_route) { + $markup .= l($edit_route['name'], $edit_route['url']) . '
'; + } + return array( '#type' => 'markup', - '#markup' => '', + '#markup' => $markup, ); - foreach ($edit_registry AS $edit_route) { - $output['#markup'] .= l($edit_route['name'], $edit_route['url']) . '
'; - } - return $output; } diff --git a/islandora.module b/islandora.module index f60627c1..171c03e1 100644 --- a/islandora.module +++ b/islandora.module @@ -155,7 +155,7 @@ function islandora_menu() { $items['islandora/object/%islandora_object/datastream/%islandora_datastream'] = array( 'title' => 'View datastream', 'page callback' => 'islandora_view_datastream', - 'page arguments' => array(4), + 'page arguments' => array(4, FALSE), 'type' => MENU_CALLBACK, 'file' => 'includes/datastream.inc', 'access callback' => 'islandora_object_datastream_access_callback', @@ -176,10 +176,10 @@ function islandora_menu() { 'access arguments' => array(FEDORA_VIEW, 2, 4), 'load arguments' => array('%map'), ); - $items['islandora/object/%islandora_object/datastream/%islandora_datastreams/edit'] = array( + $items['islandora/object/%islandora_object/datastream/%islandora_datastream/edit'] = array( 'title' => 'Edit datastream', 'page callback' => 'islandora_edit_datastream', - 'page arguments' => array(2, 4), + 'page arguments' => array(4), 'type' => MENU_CALLBACK, 'file' => 'includes/datastream.inc', 'access callback' => 'islandora_object_datastream_access_callback', diff --git a/theme/islandora.theme.inc b/theme/islandora.theme.inc index eaef7b60..7cac4d1a 100644 --- a/theme/islandora.theme.inc +++ b/theme/islandora.theme.inc @@ -38,7 +38,7 @@ function islandora_preprocess_islandora_default_edit(&$variables) { array('class' => 'datastream-mime', 'data' => $ds->mimeType), array('class' => 'datastream-size', 'data' => islandora_datastream_get_human_readable_size($ds)), array('class' => 'datastream-download', 'data' => l(t('download'), islandora_datastream_get_url($ds, 'download'))), - array('class' => 'datstream-edit', 'data' => islandora_datastream_edit_get_link($islandora_object, $ds->id)), + array('class' => 'datstream-edit', 'data' => islandora_datastream_edit_get_link($ds)), array('class' => 'datastream-delete', 'data' => islandora_datastream_get_delete_link($ds)), ); }