From 4adf1be6f67469962a4eedb904e0cf7eac828a59 Mon Sep 17 00:00:00 2001 From: willtp87 Date: Wed, 16 Sep 2015 14:49:39 -0300 Subject: [PATCH] Allowing derivatives to be altered. --- includes/derivatives.inc | 74 +++++++++++++++++++++++++--------------- islandora.api.php | 19 +++++++++++ 2 files changed, 66 insertions(+), 27 deletions(-) diff --git a/includes/derivatives.inc b/includes/derivatives.inc index 74ca2f76..ccd8c0d3 100644 --- a/includes/derivatives.inc +++ b/includes/derivatives.inc @@ -79,28 +79,26 @@ function islandora_run_derivatives(AbstractObject $object, $dsid) { * watchdog if not defined. */ function islandora_do_derivatives(AbstractObject $object, array $options) { - module_load_include('inc', 'islandora', 'includes/utilities'); - $options += array( - 'force' => FALSE, - ); - $hooks = islandora_invoke_hook_list(ISLANDORA_DERIVATIVE_CREATION_HOOK, $object->models, array($object)); - uasort($hooks, 'drupal_sort_weight'); $results = array(); - $hooks = islandora_filter_derivatives($hooks, $options, $object); - - foreach ($hooks as $hook) { - if (isset($hook['file'])) { - require_once $hook['file']; + $derivatives = islandora_get_derivative_list($object, $options); + foreach ($derivatives as $derivative) { + if (isset($derivative['file'])) { + require_once $derivative['file']; } - foreach ($hook['function'] as $function) { + foreach ($derivative['function'] as $function) { if (function_exists($function)) { - $logging = call_user_func($function, $object, $options['force'], $hook); + $logging = call_user_func($function, $object, $options['force'], $derivative); if (!empty($logging)) { $results[] = $logging; } } else { - watchdog('islandora', 'Unable to call derivative function @function as it was not found!', array('@function' => $function), WATCHDOG_ERROR); + watchdog( + 'islandora', + 'Unable to call derivative function @function as it was not found!', + array('@function' => $function), + WATCHDOG_ERROR + ); } } } @@ -172,21 +170,14 @@ function islandora_derivative_logging(array $logging_results) { * An array of operations to be called from within a batch. */ function islandora_do_batch_derivatives(AbstractObject $object, array $options) { - module_load_include('inc', 'islandora', 'includes/utilities'); - $options += array( - 'force' => FALSE, - ); - $hooks = islandora_invoke_hook_list(ISLANDORA_DERIVATIVE_CREATION_HOOK, $object->models, array($object)); - uasort($hooks, 'drupal_sort_weight'); $operations = array(); - - $hooks = islandora_filter_derivatives($hooks, $options, $object); - foreach ($hooks as $hook) { + $derivatives = islandora_get_derivative_list($object, $options); + foreach ($derivatives as $derivative) { $file = FALSE; - if (isset($hook['file'])) { - $file = $hook['file']; + if (isset($derivative['file'])) { + $file = $derivative['file']; } - foreach ($hook['function'] as $function) { + foreach ($derivative['function'] as $function) { $operations[] = array( 'islandora_derivative_perform_batch_operation', array( @@ -194,7 +185,7 @@ function islandora_do_batch_derivatives(AbstractObject $object, array $options) $file, $object->id, $options['force'], - $hook, + $derivative, ), ); } @@ -284,3 +275,32 @@ function islandora_remove_defer_derivatives_flag(AbstractObject $object) { RELS_TYPE_PLAIN_LITERAL ); } + +/** + * Get the list of derivatives. + * + * @param AbstractObject $object + * The object to find derivatives for. + * @param &array $options + * Options for derivatives, will be updated to default force to FALSE. + */ +function islandora_get_derivative_list(AbstractObject $object, &$options) { + module_load_include('inc', 'islandora', 'includes/utilities'); + + $options += array( + 'force' => FALSE, + ); + + $derivatives = islandora_invoke_hook_list( + ISLANDORA_DERIVATIVE_CREATION_HOOK, + $object->models, + array($object) + ); + + foreach (islandora_build_hook_list(ISLANDORA_DERIVATIVE_CREATION_HOOK, $object->models) as $hook) { + drupal_alter($hook, $derivatives, $object); + } + + uasort($derivatives, 'drupal_sort_weight'); + return islandora_filter_derivatives($derivatives, $options, $object); +} diff --git a/islandora.api.php b/islandora.api.php index 30b8623a..e55fd649 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -733,6 +733,25 @@ function hook_cmodel_pid_islandora_derivative() { } +/** + * Allows for the altering of defined derivative functions. + */ +function hook_islandora_derivative_alter(&$derivatives, AbstractObject $object) { + foreach ($derivatives as $key => $derivative) { + if ($derivative['destination_dsid'] == 'TN') { + unset($derivatives[$key]); + } + } +} + +/** + * Content model specific version of hook_islandora_derivative_alter(). + * + * @see hook_islandora_derivative_alter() + */ +function hook_cmodel_pid_islandora_derivative_alter() { +} + /** * Retrieves PIDS of related objects for property updating. *