Browse Source

Update to include two separate metadata callbacks as opposed to one.

pull/409/head
Jordan Dukart 11 years ago
parent
commit
a7bd089e2b
  1. 63
      includes/metadata.inc
  2. 3
      islandora.api.php
  3. 14
      islandora.module
  4. 20
      theme/islandora-dublin-core-description.tpl.php
  5. 18
      theme/islandora-dublin-core-display.tpl.php
  6. 18
      theme/theme.inc

63
includes/metadata.inc

@ -16,13 +16,39 @@
function islandora_retrieve_metadata_markup(AbstractObject $object) { function islandora_retrieve_metadata_markup(AbstractObject $object) {
$viewers = module_invoke_all('islandora_metadata_display_info'); $viewers = module_invoke_all('islandora_metadata_display_info');
$viewer = variable_get('islandora_metadata_display', 'dublin_core'); $viewer = variable_get('islandora_metadata_display', 'dublin_core');
$markup = '';
if (isset($viewers[$viewer]['callback'])) { if (isset($viewers[$viewer]['metadata callback'])) {
return call_user_func($viewers[$viewer]['callback'], $object); $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 $markup;
return ''; }
/**
* 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); 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);
}

3
islandora.api.php

@ -714,7 +714,8 @@ function hook_islandora_metadata_display_info() {
'hookable_displays_yay' => array( 'hookable_displays_yay' => array(
'label' => t('Hookable display yay!'), 'label' => t('Hookable display yay!'),
'description' => t('This is purely an example of how to implement this.'), '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', 'configuration' => 'admin/hookable_displays_yay/somepath',
), ),
); );

14
islandora.module

@ -464,6 +464,17 @@ function islandora_theme() {
'pattern' => 'islandora_dublin_core_display__', 'pattern' => 'islandora_dublin_core_display__',
'variables' => array('islandora_object' => NULL), '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( 'dublin_core' => array(
'label' => t('Dublin Core'), 'label' => t('Dublin Core'),
'description' => t('Dublin Core metadata'), 'description' => t('Dublin Core metadata'),
'callback' => 'islandora_metadata_display_callback', 'metadata callback' => 'islandora_metadata_display_callback',
'description callback' => 'islandora_metadata_description_callback',
), ),
); );
} }

20
theme/islandora-dublin-core-description.tpl.php

@ -0,0 +1,20 @@
<?php
/**
* @file
* This is the template file for the Dublin Core metadata description.
*
* Available variables:
* - $islandora_object: The Islandora object rendered in this template file
* $dc_array: The DC datastream object values as a sanitized array. This
* includes label, value and class name.
*
* @see template_preprocess_islandora_dublin_core_description()
* @see theme_islandora_dublin_core_description()
*/
?>
<div class="islandora-metadata-sidebar">
<?php if (!empty($dc_array['dc:description']['value'])): ?>
<h2><?php print $dc_array['dc:description']['label']; ?></h2>
<p property="description"><?php print $dc_array['dc:description']['value']; ?></p>
<?php endif; ?>
</div>

18
theme/islandora-dublin-core-display.tpl.php

@ -1,3 +1,21 @@
<?php
/**
* @file
* This is the template file for the object page for large image
*
* Available variables:
* - $islandora_object: The Islandora object rendered in this template file
* - $islandora_dublin_core: The DC datastream object
* - $dc_array: The DC datastream object values as a sanitized array. This
* includes label, value and class name.
* - $islandora_object_label: The sanitized object label.
* - $parent_collections: An array containing parent collection(s) info.
* Includes collection object, label, url and rendered link.
*
* @see template_preprocess_islandora_dublin_core_display()
* @see theme_islandora_dublin_core_display()
*/
?>
<fieldset class="collapsible collapsed"> <fieldset class="collapsible collapsed">
<legend><span class="fieldset-legend"><?php print t('Details'); ?></span></legend> <legend><span class="fieldset-legend"><?php print t('Details'); ?></span></legend>
<div class="fieldset-wrapper"> <div class="fieldset-wrapper">

18
theme/theme.inc

@ -438,6 +438,22 @@ function islandora_preprocess_islandora_dublin_core_display(array &$variables) {
drupal_set_message(t('Error retrieving object %s %t', array('%s' => $islandora_object->id, '%t' => $e->getMessage())), 'error', FALSE); drupal_set_message(t('Error retrieving object %s %t', array('%s' => $islandora_object->id, '%t' => $e->getMessage())), 'error', FALSE);
} }
} }
$variables['islandora_dublin_core'] = isset($dc_object) ? $dc_object : NULL;
$variables['dc_array'] = isset($dc_object) ? $dc_object->asArray() : array(); $variables['dc_array'] = isset($dc_object) ? $dc_object->asArray() : array();
} }
/**
* Implements hook_preprocess().
*/
function islandora_preprocess_islandora_dublin_core_description(array &$variables) {
$islandora_object = $variables['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);
}
}
$variables['dc_array'] = isset($dc_object) ? $dc_object->asArray() : array();
}
Loading…
Cancel
Save