Browse Source

Merge branch '7.x-hookable-metadata' of github.com:jordandukart/islandora into 7.x

pull/457/head
Nelson Hart 11 years ago
parent
commit
810f7ef7c7
  1. 2
      includes/derivatives.inc
  2. 123
      includes/metadata.inc
  3. 60
      islandora.api.php
  4. 36
      islandora.module
  5. 17
      theme/islandora-dublin-core-display.tpl.php
  6. 18
      theme/theme.inc

2
includes/derivatives.inc

@ -37,7 +37,7 @@ function islandora_do_derivatives(AbstractObject $object, array $options) {
$options += array(
'force' => FALSE,
);
$hooks = islandora_invoke_hook_list(ISLANDORA_DERVIATIVE_CREATION_HOOK, $object->models, array());
$hooks = islandora_invoke_hook_list(ISLANDORA_DERVIATIVE_CREATION_HOOK, $object->models, array($object));
uasort($hooks, 'drupal_sort_weight');
$results = array();

123
includes/metadata.inc

@ -0,0 +1,123 @@
<?php
/**
* @file
* Defines functions used when viewing metadata displays on Islandora objects.
*/
/**
* Retrieves the metadata display markup for an Islandora object.
*
* @param AbstractObject $object
* An AbstractObject representing an object within Fedora.
*
* @return string
* Markup to be rendered for display on Islandora object pages.
*/
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);
}
else {
return '';
}
}
/**
* Form used for choosing which default metadata display to use for viewing.
*
* @param array $form
* An array representing a Drupal form.
* @param array $form_state
* An array containing the Drupal form state.
*
* @return array
* An array representing the metadata display viewer form.
*/
function islandora_metadata_display_form($form, $form_state) {
module_load_include('inc', 'islandora', 'includes/solution_packs.inc');
$form = array();
$defined_displays = module_invoke_all('islandora_metadata_display_info');
if (!empty($defined_displays)) {
$no_viewer = array();
$no_viewer['none'] = array(
'label' => t('None'),
'description' => t("Don't show any metadata for displaying"),
);
$viewers = array_merge_recursive($no_viewer, $defined_displays);
$form['viewers'] = array(
'#type' => 'item',
'#title' => t('Select a viewer'),
'#description' => t('Preferred metadata display for Islandora. These may be provided by third-party modules.'),
'#tree' => TRUE,
'#theme' => 'islandora_viewers_table',
);
foreach ($viewers as $name => $profile) {
$options[$name] = '';
$form['viewers']['name'][$name] = array(
'#type' => 'hidden',
'#value' => $name,
);
$form['viewers']['label'][$name] = array(
'#type' => 'item',
'#markup' => $profile['label'],
);
$form['viewers']['description'][$name] = array(
'#type' => 'item',
'#markup' => $profile['description'],
);
$form['viewers']['configuration'][$name] = array(
'#type' => 'item',
'#markup' => (isset($profile['configuration']) AND $profile['configuration'] != '') ? l(t('configure'), $profile['configuration']) : '',
);
}
$form['viewers']['default'] = array(
'#type' => 'radios',
'#options' => isset($options) ? $options : array(),
'#default_value' => variable_get('islandora_metadata_display', 'dublin_core'),
);
}
else {
$form['viewers']['no_viewers'] = array(
'#markup' => t('No viewers detected.'),
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
return $form;
}
/**
* Submit handler for the metadata display form which sets the default viewer.
*
* @param array $form
* An array representing a Drupal form.
* @param array $form_state
* An array containing the Drupal form state.
*/
function islandora_metadata_display_form_submit($form, $form_state) {
variable_set('islandora_metadata_display', $form_state['values']['viewers']['default']);
drupal_set_message(t('The configuration options have been saved.'));
}
/**
* Metadata display callback for rendering Dublin Core metadata.
*
* @param AbstractObject $object
* An AbstractObject representing an object within Fedora.
*
* @return string
* Markup representing the rendered metadata from Dublin Core.
*/
function islandora_metadata_display_callback(AbstractObject $object) {
$elements = array(
'islandora_object' => $object,
);
return theme('islandora_dublin_core_display', $elements);
}

60
islandora.api.php

@ -394,8 +394,17 @@ function hook_islandora_viewer_info() {
/**
* Returns a list of datastreams that are determined to be undeletable.
*
* The list is used to prevent delete links from being shown.
*
* @param array $models
* An array of content models for the current object.
*
* @return array
* An array of DSIDs that shouldn't be deleted.
*/
function hook_islandora_undeletable_datastreams(array $models) {
return array('DC', 'MODS');
}
/**
@ -578,6 +587,8 @@ function hook_CMODEL_PID_islandora_overview_object_alter(AbstractObject &$object
/*
* Defines derivative functions to be executed based on certain conditions.
*
* @param AbstractObject $object
* Object to which derivatives will be added
* This hook fires when an object/datastream is ingested or a datastream is
* modified.
*
@ -611,33 +622,38 @@ function hook_CMODEL_PID_islandora_overview_object_alter(AbstractObject &$object
* - file: A string denoting the path to the file where the function
* is being called from.
*/
function hook_islandora_derivative() {
return array(
array(
function hook_islandora_derivative(AbstractObject $object) {
$derivatives[] = array(
'source_dsid' => 'OBJ',
'destination_dsid' => 'DERIV',
'weight' => '0',
'function' => array(
'islandora_derivatives_test_create_deriv_datastream',
),
),
array(
);
// Test object before adding this derivative.
if ($object['SOMEWEIRDDATASTREAM']->mimetype == "SOMETHING/ODD") {
$derivatives[] = array(
'source_dsid' => 'SOMEWEIRDDATASTREAM',
'destination_dsid' => 'STANLEY',
'weight' => '-1',
'function' => array(
'islandora_derivatives_test_create_some_weird_datastream',
),
),
array(
);
}
$derivatives[] = array(
'source_dsid' => NULL,
'destination_dsid' => 'NOSOURCE',
'weight' => '-3',
'function' => array(
'islandora_derivatives_test_create_nosource_datastream',
),
),
);
return $derivatives;
}
/**
@ -675,3 +691,31 @@ function hook_islandora_update_related_objects_properties(AbstractObject $object
function hook_islandora_breadcrumbs_alter(&$breadcrumbs, $context) {
}
/**
* Registry hook for metadata display viewers.
*
* Modules can use this hook to override the default Dublin Core display.
* This hook lets Islandora know which viewers there are available.
*
* @return array
* An associative array where the values are the following:
* -label: Human readable display label for selection.
* -description: A description of what the metadata display viewer does.
* -callback: A callable function that provides the markup to be passed
* off to the template files.
* -configuration (Optional): A path to the administration page for the
* metadata display.
* @see islandora_retrieve_metadata_markup()
*/
function hook_islandora_metadata_display_info() {
return array(
'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',
'configuration' => 'admin/hookable_displays_yay/somepath',
),
);
}

36
islandora.module

@ -99,6 +99,14 @@ function islandora_menu() {
'type' => MENU_NORMAL_ITEM,
'weight' => -1,
);
$items['admin/islandora/metadata'] = array(
'title' => 'Metadata Display',
'description' => 'Configure settings for metadata display on Islandora objects',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_metadata_display_form'),
'file' => 'includes/metadata.inc',
'access arguments' => array('adminisiter site configuration'),
);
$items['admin/islandora/solution_packs'] = array(
'title' => 'Solution packs',
'description' => 'Install content models and collections required by installed solution packs.',
@ -445,6 +453,17 @@ function islandora_theme() {
'file' => 'theme/theme.inc',
'variables' => array('datastream' => NULL),
),
'islandora_dublin_core_display' => array(
'file' => 'theme/theme.inc',
'template' => 'theme/islandora-dublin-core-display',
// 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-display--islandora-27.tpl.php".
'pattern' => 'islandora_dublin_core_display__',
'variables' => array('islandora_object' => NULL),
),
);
}
@ -1237,10 +1256,10 @@ function islandora_islandora_required_objects(IslandoraTuque $connection) {
}
/**
* Implements islandora_undeleteable_datastreams().
* Implements hook_islandora_undeleteable_datastreams().
*/
function islandora_islandora_undeletable_datastreams(array $models) {
return array('DC');
return array('DC', 'RELS-EXT');
}
/**
@ -1602,3 +1621,16 @@ function islandora_islandora_datastream_modified(AbstractObject $object, Abstrac
));
islandora_derivative_logging($logging_results);
}
/**
* Implements hook_islandora_metadata_display_info().
*/
function islandora_islandora_metadata_display_info() {
return array(
'dublin_core' => array(
'label' => t('Dublin Core'),
'description' => t('Dublin Core metadata'),
'callback' => 'islandora_metadata_display_callback',
),
);
}

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

@ -0,0 +1,17 @@
<fieldset class="collapsible collapsed">
<legend><span class="fieldset-legend"><?php print t('Details'); ?></span></legend>
<div class="fieldset-wrapper">
<dl xmlns:dcterms="http://purl.org/dc/terms/" class="islandora-inline-metadata islandora-metadata-fields">
<?php $row_field = 0; ?>
<?php foreach($dc_array as $key => $value): ?>
<dt property="<?php print $value['dcterms']; ?>" content="<?php print $value['value']; ?>" class="<?php print $value['class']; ?><?php print $row_field == 0 ? ' first' : ''; ?>">
<?php print $value['label']; ?>
</dt>
<dd class="<?php print $value['class']; ?><?php print $row_field == 0 ? ' first' : ''; ?>">
<?php print $value['value']; ?>
</dd>
<?php $row_field++; ?>
<?php endforeach; ?>
</dl>
</div>
</fieldset>

18
theme/theme.inc

@ -423,3 +423,21 @@ function theme_islandora_datastream_version_link(array $vars) {
return '';
}
}
/**
* Implements hook_preprocess().
*/
function islandora_preprocess_islandora_dublin_core_display(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['islandora_dublin_core'] = isset($dc_object) ? $dc_object : NULL;
$variables['dc_array'] = isset($dc_object) ? $dc_object->asArray() : array();
}

Loading…
Cancel
Save