diff --git a/includes/metadata.inc b/includes/metadata.inc index 49b6e417..9f8a51ed 100644 --- a/includes/metadata.inc +++ b/includes/metadata.inc @@ -16,13 +16,39 @@ function islandora_retrieve_metadata_markup(AbstractObject $object) { $viewers = module_invoke_all('islandora_metadata_display_info'); $viewer = variable_get('islandora_metadata_display', 'dublin_core'); - - if (isset($viewers[$viewer]['callback'])) { - return call_user_func($viewers[$viewer]['callback'], $object); + $markup = ''; + if (isset($viewers[$viewer]['metadata callback'])) { + $markup = call_user_func($viewers[$viewer]['metadata callback'], $object); + // The callback doesn't have any markup provided for this particular object, + // default back to the dublin_core display. + if ($markup === FALSE) { + $markup = call_user_func($viewers['dublin_core']['metadata callback'], $object); + } } - else { - return ''; + return $markup; +} + +/** + * Retrieves the metadata display description for an Islandora object. + * + * @param AbstractObject $object + * An AbstractObject representing an object within Fedora. + * @return string + * Markup to be rendered for description on Islandora object pages. + */ +function islandora_retrieve_description_markup(AbstractObject $object) { + $viewers = module_invoke_all('islandora_metadata_display_info'); + $viewer = variable_get('islandora_metadata_display', 'dublin_core'); + $markup = ''; + if (isset($viewers[$viewer]['description callback'])) { + $markup = call_user_func($viewers[$viewer]['description callback'], $object); + // The callback doesn't have any markup provided for this particular object, + // default back to the dublin_core display. + if ($markup === FALSE) { + $markup = call_user_func($viewers['dublin_core']['description callback'], $object); + } } + return $markup; } /** @@ -121,3 +147,30 @@ function islandora_metadata_display_callback(AbstractObject $object) { ); return theme('islandora_dublin_core_display', $elements); } + +/** + * Metadata description callback for rendering Dublin Core description. + * + * @param AbstractObject $object + * An AbstractObject representing an object within Fedora. + * + * @return string + * Markup representing the rendered metadata from Dublin Core. + */ +function islandora_metadata_description_callback(AbstractObject $islandora_object) { + if (islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $islandora_object['DC'])) { + try { + $dc = $islandora_object['DC']->content; + $dc_object = DublinCore::importFromXMLString($dc); + } + catch (Exception $e) { + drupal_set_message(t('Error retrieving object %s %t', array('%s' => $islandora_object->id, '%t' => $e->getMessage())), 'error', FALSE); + } + } + $dc_array = isset($dc_object) ? $dc_object->asArray() : array(); + $elements = array( + 'islandora_object' => $islandora_object, + 'dc_array' => $dc_array, + ); + return theme('islandora_dublin_core_description', $elements); +} \ No newline at end of file diff --git a/islandora.api.php b/islandora.api.php index bed9b401..b942052d 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -714,7 +714,8 @@ function hook_islandora_metadata_display_info() { 'hookable_displays_yay' => array( 'label' => t('Hookable display yay!'), 'description' => t('This is purely an example of how to implement this.'), - 'callback' => 'hookable_displays_some_function_that_returns_markup', + 'metadata callback' => 'hookable_displays_some_function_that_returns_metadata_markup', + 'description callback' => 'hookable_displays_some_function_that_returns_description_markup', 'configuration' => 'admin/hookable_displays_yay/somepath', ), ); diff --git a/islandora.module b/islandora.module index f8e97c71..2179d292 100644 --- a/islandora.module +++ b/islandora.module @@ -464,6 +464,17 @@ function islandora_theme() { 'pattern' => 'islandora_dublin_core_display__', 'variables' => array('islandora_object' => NULL), ), + 'islandora_dublin_core_description' => array( + 'file' => 'theme/theme.inc', + 'template' => 'theme/islandora-dublin-core-description', + // We can add PIDs to the end of this pattern in our preprocess function + // and templates will be able to have have a pid appended to the + // template name to overide a template on a per object basis. + // An example template might be named: + // "islandora-dublin-core-description--islandora-27.tpl.php". + 'pattern' => 'islandora_dublin_core_description__', + 'variables' => array('islandora_object' => NULL), + ), ); } @@ -1630,7 +1641,8 @@ function islandora_islandora_metadata_display_info() { 'dublin_core' => array( 'label' => t('Dublin Core'), 'description' => t('Dublin Core metadata'), - 'callback' => 'islandora_metadata_display_callback', + 'metadata callback' => 'islandora_metadata_display_callback', + 'description callback' => 'islandora_metadata_description_callback', ), ); } diff --git a/theme/islandora-dublin-core-description.tpl.php b/theme/islandora-dublin-core-description.tpl.php new file mode 100644 index 00000000..2ff54cdc --- /dev/null +++ b/theme/islandora-dublin-core-description.tpl.php @@ -0,0 +1,20 @@ + +
diff --git a/theme/islandora-dublin-core-display.tpl.php b/theme/islandora-dublin-core-display.tpl.php index 63fc60a6..0dbc9235 100644 --- a/theme/islandora-dublin-core-display.tpl.php +++ b/theme/islandora-dublin-core-display.tpl.php @@ -1,3 +1,21 @@ +