From 0ae1a25b739e280ce6f95af908cb3d5642d34390 Mon Sep 17 00:00:00 2001 From: Matthew Perry Date: Fri, 13 Nov 2015 16:26:43 -0400 Subject: [PATCH 1/5] Added a drupal alter to allow for other modules to modify the datastream edit registry after it has been built. --- includes/datastream.inc | 9 ++++++++- islandora.api.php | 25 +++++++++++++++++++++++++ islandora.module | 1 + 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/includes/datastream.inc b/includes/datastream.inc index 44a27ba9..ece5a45a 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -295,6 +295,12 @@ function islandora_datastream_get_url(AbstractDatastream $datastream, $type = 'd */ function islandora_edit_datastream(AbstractDatastream $datastream) { $edit_registry = module_invoke_all('islandora_edit_datastream_registry', $datastream->parent, $datastream); + $context = array( + 'datastream_parent' => $datastream->parent, + 'datastream' => $datastream, + 'original_edit_registry' => $edit_registry, + ); + drupal_alter(ISLANDORA_EDIT_DATASTREAM_MODIFY_REGISTRY_HOOK, $edit_registry, $context); $edit_count = count($edit_registry); switch ($edit_count) { case 0: @@ -305,7 +311,8 @@ function islandora_edit_datastream(AbstractDatastream $datastream) { case 1: // One registry implementation, go there. - drupal_goto($edit_registry[0]['url']); + $edit_registry = reset($edit_registry); + drupal_goto($edit_registry['url']); break; default: diff --git a/islandora.api.php b/islandora.api.php index e55fd649..a23d31be 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -849,3 +849,28 @@ 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: + * - datastream_parent: The datastream parent. + * - datastream: The datastream being edited. + * - original_edit_registry: The original edit_registry prior to any + * modifications. + */ +function hook_islandora_edit_datastream_modify_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['datastream_parent']->id}/{$context['datastream']->id}", + 'weight' => 1, + ); +} diff --git a/islandora.module b/islandora.module index ccab3773..e3eeada7 100644 --- a/islandora.module +++ b/islandora.module @@ -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_MODIFY_REGISTRY_HOOK', 'islandora_edit_datastream_modify_registry'); // @todo Add Documentation. define('ISLANDORA_OBJECT_INGESTED_HOOK', 'islandora_object_ingested'); From 42f322930c6de421d33d313e060f038b0f408c59 Mon Sep 17 00:00:00 2001 From: Matthew Perry Date: Mon, 16 Nov 2015 11:13:22 -0400 Subject: [PATCH 2/5] Moved building the edit registry to an includes function and changed teh context index. --- includes/datastream.inc | 10 +++------- includes/utilities.inc | 22 ++++++++++++++++++++++ islandora.api.php | 2 +- theme/theme.inc | 3 ++- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/includes/datastream.inc b/includes/datastream.inc index ece5a45a..8fff2e5a 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -294,13 +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); - $context = array( - 'datastream_parent' => $datastream->parent, - 'datastream' => $datastream, - 'original_edit_registry' => $edit_registry, - ); - drupal_alter(ISLANDORA_EDIT_DATASTREAM_MODIFY_REGISTRY_HOOK, $edit_registry, $context); + module_load_include('inc', 'islandora', 'includes/utilities'); + + $edit_registry = islandora_build_datastream_edit_registry($datastream->parent, $datastream); $edit_count = count($edit_registry); switch ($edit_count) { case 0: diff --git a/includes/utilities.inc b/includes/utilities.inc index 8e071def..fa9b7594 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -946,3 +946,25 @@ function islandora_deployed_on_windows() { } return FALSE; } + +/** + * Build the edit registry for a given datastream. + * + * @param AbstractObject $object + * The object being edited. + * @param AbstractDatastream $datastream + * The datastream being edited. + * + * @return array + * The built edit registry array. + */ +function islandora_build_datastream_edit_registry($object, $datastream) { + $edit_registry = module_invoke_all('islandora_edit_datastream_registry', $object, $datastream); + $context = array( + 'object' => $object, + 'datastream' => $datastream, + 'original_edit_registry' => $edit_registry, + ); + drupal_alter(ISLANDORA_EDIT_DATASTREAM_MODIFY_REGISTRY_HOOK, $edit_registry, $context); + return $edit_registry; +} diff --git a/islandora.api.php b/islandora.api.php index a23d31be..31f1c055 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -870,7 +870,7 @@ function hook_islandora_edit_datastream_modify_registry_alter(&$edit_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['datastream_parent']->id}/{$context['datastream']->id}", + 'url' => "islandora/custom_form/{$context['object']->id}/{$context['datastream']->id}", 'weight' => 1, ); } diff --git a/theme/theme.inc b/theme/theme.inc index 1ddad1db..cd08ee12 100644 --- a/theme/theme.inc +++ b/theme/theme.inc @@ -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->parent, $datastream); $can_edit = count($edit_registry) > 0 && islandora_datastream_access(ISLANDORA_METADATA_EDIT, $datastream); From 0e24c7f4063e2966a8e874338d8287b4b0b7c583 Mon Sep 17 00:00:00 2001 From: Matthew Perry Date: Mon, 16 Nov 2015 12:20:09 -0400 Subject: [PATCH 3/5] Updating constant. --- includes/utilities.inc | 4 ++-- islandora.api.php | 7 +++---- islandora.module | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index fa9b7594..7db58557 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -959,12 +959,12 @@ function islandora_deployed_on_windows() { * The built edit registry array. */ function islandora_build_datastream_edit_registry($object, $datastream) { - $edit_registry = module_invoke_all('islandora_edit_datastream_registry', $object, $datastream); + $edit_registry = module_invoke_all(ISLANDORA_EDIT_DATASTREAM_REGISTRY_HOOK, $object, $datastream); $context = array( 'object' => $object, 'datastream' => $datastream, 'original_edit_registry' => $edit_registry, ); - drupal_alter(ISLANDORA_EDIT_DATASTREAM_MODIFY_REGISTRY_HOOK, $edit_registry, $context); + drupal_alter(ISLANDORA_EDIT_DATASTREAM_REGISTRY_HOOK, $edit_registry, $context); return $edit_registry; } diff --git a/islandora.api.php b/islandora.api.php index 31f1c055..c88f0c20 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -857,12 +857,12 @@ function hook_islandora_get_breadcrumb_query_predicates() { * The array of registry paths. * @param array $context * An associative array containing: - * - datastream_parent: The datastream parent. + * - 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_modify_registry_alter(&$edit_registry, $context) { +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']); @@ -870,7 +870,6 @@ function hook_islandora_edit_datastream_modify_registry_alter(&$edit_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}", - 'weight' => 1, + 'url' => "islandora/custom_form/{$context['object']->id}/{$context['datastream']->id}" ); } diff --git a/islandora.module b/islandora.module index e3eeada7..25f01cbe 100644 --- a/islandora.module +++ b/islandora.module @@ -52,7 +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_MODIFY_REGISTRY_HOOK', 'islandora_edit_datastream_modify_registry'); +define('ISLANDORA_EDIT_DATASTREAM_REGISTRY_HOOK', 'islandora_edit_datastream_registry'); // @todo Add Documentation. define('ISLANDORA_OBJECT_INGESTED_HOOK', 'islandora_object_ingested'); From c66e087188d5579d3d8ec08f1e000cbe83ade8c0 Mon Sep 17 00:00:00 2001 From: Matthew Perry Date: Mon, 16 Nov 2015 13:02:36 -0400 Subject: [PATCH 4/5] Removing passing in the object to prevent any possible confusion and just using the datastream->parent. --- includes/datastream.inc | 2 +- includes/utilities.inc | 8 +++----- theme/theme.inc | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/includes/datastream.inc b/includes/datastream.inc index 8fff2e5a..1c339b61 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -296,7 +296,7 @@ function islandora_datastream_get_url(AbstractDatastream $datastream, $type = 'd function islandora_edit_datastream(AbstractDatastream $datastream) { module_load_include('inc', 'islandora', 'includes/utilities'); - $edit_registry = islandora_build_datastream_edit_registry($datastream->parent, $datastream); + $edit_registry = islandora_build_datastream_edit_registry($datastream); $edit_count = count($edit_registry); switch ($edit_count) { case 0: diff --git a/includes/utilities.inc b/includes/utilities.inc index 7db58557..dcbaab02 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -950,18 +950,16 @@ function islandora_deployed_on_windows() { /** * Build the edit registry for a given datastream. * - * @param AbstractObject $object - * The object being edited. * @param AbstractDatastream $datastream * The datastream being edited. * * @return array * The built edit registry array. */ -function islandora_build_datastream_edit_registry($object, $datastream) { - $edit_registry = module_invoke_all(ISLANDORA_EDIT_DATASTREAM_REGISTRY_HOOK, $object, $datastream); +function islandora_build_datastream_edit_registry(AbstractDatastream $datastream) { + $edit_registry = module_invoke_all(ISLANDORA_EDIT_DATASTREAM_REGISTRY_HOOK, $datastream->parent, $datastream); $context = array( - 'object' => $object, + 'object' => $datastream->parent, 'datastream' => $datastream, 'original_edit_registry' => $edit_registry, ); diff --git a/theme/theme.inc b/theme/theme.inc index cd08ee12..dea4a616 100644 --- a/theme/theme.inc +++ b/theme/theme.inc @@ -535,7 +535,7 @@ function theme_islandora_datastream_edit_link(array $vars) { $datastream = $vars['datastream']; module_load_include('inc', 'islandora', 'includes/utilities'); - $edit_registry = islandora_build_datastream_edit_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); From c70255d8ef663ad57e1ffa7579468ac80f583da1 Mon Sep 17 00:00:00 2001 From: Matthew Perry Date: Mon, 16 Nov 2015 13:07:09 -0400 Subject: [PATCH 5/5] Updating variable name. --- includes/datastream.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/datastream.inc b/includes/datastream.inc index 1c339b61..18bc5096 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -307,8 +307,8 @@ function islandora_edit_datastream(AbstractDatastream $datastream) { case 1: // One registry implementation, go there. - $edit_registry = reset($edit_registry); - drupal_goto($edit_registry['url']); + $entry = reset($edit_registry); + drupal_goto($entry['url']); break; default: