Skip to content

Commit

Permalink
Merge pull request #637 from matthewperry/7.x-ISLANDORA-1547
Browse files Browse the repository at this point in the history
ISLANDORA-1547
  • Loading branch information
ruebot committed Nov 24, 2015
2 parents c6e390c + c70255d commit e2a5f08
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
7 changes: 5 additions & 2 deletions includes/datastream.inc
Expand Up @@ -294,7 +294,9 @@ function islandora_datastream_get_url(AbstractDatastream $datastream, $type = 'd
* The datastream to edit.
*/
function islandora_edit_datastream(AbstractDatastream $datastream) {
$edit_registry = module_invoke_all('islandora_edit_datastream_registry', $datastream->parent, $datastream);
module_load_include('inc', 'islandora', 'includes/utilities');

$edit_registry = islandora_build_datastream_edit_registry($datastream);
$edit_count = count($edit_registry);
switch ($edit_count) {
case 0:
Expand All @@ -305,7 +307,8 @@ function islandora_edit_datastream(AbstractDatastream $datastream) {

case 1:
// One registry implementation, go there.
drupal_goto($edit_registry[0]['url']);
$entry = reset($edit_registry);
drupal_goto($entry['url']);
break;

default:
Expand Down
20 changes: 20 additions & 0 deletions includes/utilities.inc
Expand Up @@ -946,3 +946,23 @@ function islandora_deployed_on_windows() {
}
return FALSE;
}

/**
* Build the edit registry for a given datastream.
*
* @param AbstractDatastream $datastream
* The datastream being edited.
*
* @return array
* The built edit registry array.
*/
function islandora_build_datastream_edit_registry(AbstractDatastream $datastream) {
$edit_registry = module_invoke_all(ISLANDORA_EDIT_DATASTREAM_REGISTRY_HOOK, $datastream->parent, $datastream);
$context = array(
'object' => $datastream->parent,
'datastream' => $datastream,
'original_edit_registry' => $edit_registry,
);
drupal_alter(ISLANDORA_EDIT_DATASTREAM_REGISTRY_HOOK, $edit_registry, $context);
return $edit_registry;
}
24 changes: 24 additions & 0 deletions islandora.api.php
Expand Up @@ -849,3 +849,27 @@ function hook_islandora_get_breadcrumb_query_predicates() {
'someotherpredicate',
);
}

/**
* Use alter hook to modify registry paths before the paths are rendered.
*
* @param array $edit_registry
* The array of registry paths.
* @param array $context
* An associative array containing:
* - object: The object that owns the datastream being edited.
* - datastream: The datastream being edited.
* - original_edit_registry: The original edit_registry prior to any
* modifications.
*/
function hook_islandora_edit_datastream_registry_alter(&$edit_registry, $context) {
// Example: Remove xml form builder edit registry.
if (isset($edit_registry['xml_form_builder_edit_form_registry'])) {
unset($edit_registry['xml_form_builder_edit_form_registry']);
}
// Add custom form to replace the removed form builder edit_form.
$edit_registry['somemodule_custom_form'] = array(
'name' => t('Somemodule Custom Form'),
'url' => "islandora/custom_form/{$context['object']->id}/{$context['datastream']->id}"
);
}
1 change: 1 addition & 0 deletions islandora.module
Expand Up @@ -52,6 +52,7 @@ define('ISLANDORA_UPDATE_RELATED_OBJECTS_PROPERTIES_HOOK', 'islandora_update_rel
define('ISLANDORA_METADATA_OBJECT_ALTER', 'islandora_metadata_object');
define('ISLANDORA_METADATA_OBJECT_DESCRIPTION_ALTER', 'islandora_metadata_object_description');
define('ISLANDORA_BREADCRUMB_FILTER_PREDICATE_HOOK', 'islandora_get_breadcrumb_query_predicates');
define('ISLANDORA_EDIT_DATASTREAM_REGISTRY_HOOK', 'islandora_edit_datastream_registry');

// @todo Add Documentation.
define('ISLANDORA_OBJECT_INGESTED_HOOK', 'islandora_object_ingested');
Expand Down
3 changes: 2 additions & 1 deletion theme/theme.inc
Expand Up @@ -533,8 +533,9 @@ function theme_islandora_datastream_revert_link(array $vars) {
*/
function theme_islandora_datastream_edit_link(array $vars) {
$datastream = $vars['datastream'];
module_load_include('inc', 'islandora', 'includes/utilities');

$edit_registry = module_invoke_all('islandora_edit_datastream_registry', $datastream->parent, $datastream);
$edit_registry = islandora_build_datastream_edit_registry($datastream);

$can_edit = count($edit_registry) > 0 && islandora_datastream_access(ISLANDORA_METADATA_EDIT, $datastream);

Expand Down

0 comments on commit e2a5f08

Please sign in to comment.