From a462a4448cd50bb4d075ac97f4c146ace5940bab Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Tue, 16 Apr 2013 16:48:37 -0300 Subject: [PATCH] Ingest functionality of the ingest form is now a callback. --- includes/ingest.form.inc | 22 ++++++++++++++-------- islandora.api.php | 2 +- islandora.module | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index 9a6c2b9c..53c48639 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -288,7 +288,9 @@ function islandora_ingest_form_execute_step(array $form, array &$form_state, $st break; case 'callback': - call_user_func_array($step['do_function']['function'], $step['do_function']['args']); + $args = array(&$form_state); + $args = isset($step['do_function']['args']) ? array_merge($args, $step['do_function']['args']) : $args; + call_user_func_array($step['do_function']['function'], $args); $next_step = islandora_ingest_form_get_next_step_id($form_state); if ($next_step) { islandora_ingest_form_increment_step($form_state); @@ -470,7 +472,9 @@ function islandora_ingest_form_callback_previous(array $form, array &$form_state $step = islandora_ingest_form_get_step($form_state, $keys[$current_step]); islandora_ingest_form_decrement_step($form_state); if ($step['type'] === 'callback') { - call_user_func_array($step['undo_function']['function'], $step['undo_function']['args']); + $args = array(&$form_state); + $args = isset($step['undo_function']['args']) ? array_merge($args, $step['undo_function']['args']) : $args; + call_user_func_array($step['undo_function']['function'], $args); } else { $form = TRUE; @@ -583,7 +587,10 @@ function islandora_ingest_form_ingest_button(array &$form_state) { $validate_callback = $form_id . '_validate'; $validate = function_exists($validate_callback) ? array($validate_callback) : NULL; $submit_callback = $form_id . '_submit'; - $submit = function_exists($submit_callback) ? array($submit_callback, 'islandora_ingest_form_submit') : array('islandora_ingest_form_submit'); + $submit = array(); + if (function_exists($submit_callback)) { + $submit[] = $submit_callback; + } // Because of callback shananigans we have to check if there are a chain of // n callbacks that are weighted after the current step. @@ -607,12 +614,10 @@ function islandora_ingest_form_ingest_button(array &$form_state) { * * Attempts to ingest every object built by the previous steps. * - * @param array $form - * The Drupal form. * @param array $form_state * The Drupal form state. */ -function islandora_ingest_form_submit(array $form, array &$form_state) { +function islandora_ingest_form_ingest(array &$form_state) { foreach ($form_state['islandora']['objects'] as $object) { try { islandora_add_object($object); @@ -644,7 +649,9 @@ function islandora_ingest_form_callback_ingest(array $form, array &$form_state) // Execute our n chain of callbacks. while ($current_step < count($steps)) { $step = islandora_ingest_form_get_step($form_state, $keys[$current_step]); - call_user_func_array($step['do_function']['function'], $step['do_function']['args']); + $args = array(&$form_state); + $args = isset($step['do_function']['args']) ? array_merge($args, $step['do_function']['args']) : $args; + call_user_func_array($step['do_function']['function'], $args); $current_step++; } } @@ -790,7 +797,6 @@ function islandora_ingest_form_get_steps(array &$form_state) { '@module' => $step['module'], '@step' => $key, ), WATCHDOG_ERROR); - dd('errorsaursu'); unset($steps[$key]); } } diff --git a/islandora.api.php b/islandora.api.php index fbe49be6..f6fd02a7 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -405,7 +405,7 @@ function hook_islandora_undeletable_datastreams(array $models) { * end of the process while smaller(/"lighter") values are executed first. * Both types may optionally include: * - module: A module from which we want to load an include. - * "Form type" may optionally include: + * "Form" type may optionally include: * - file: A file to include (relative to the module's path, including the * file's extension). */ diff --git a/islandora.module b/islandora.module index ad9e569e..6f1d0144 100644 --- a/islandora.module +++ b/islandora.module @@ -1097,3 +1097,21 @@ function islandora_download_clip(AbstractObject $object) { } exit(); } + +/** + * Implements hook_islandora_ingest_steps(). + */ +function islandora_islandora_ingest_steps(&$form_state) { + return array( + 'islandora_ingest_form_submit' => array( + 'type' => 'callback', + 'weight' => 50, + 'do_function' => array( + 'function' => 'islandora_ingest_form_ingest', + ), + 'undo_function' => array( + 'function' => 'islandora_ingest_form_undo_ingest', + ), + ), + ); +}