From 3bb2646b5e1b1fb570fa177bb4febca5293177c1 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Tue, 30 Apr 2013 16:51:17 +0200 Subject: [PATCH 1/4] Added a convience function for generated depreciated function messages. The message will only be displayed to the user if Drupal is configured to show these warnings, regardless of the setting though it will be logged to the watchdog. --- includes/utilities.inc | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/includes/utilities.inc b/includes/utilities.inc index fbc4585a..aac770e2 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -817,3 +817,36 @@ function islandora_content_model_select_table_form_element($drupal_variable, $de return $element; } + +/** + * Convience function for generating a E_USER_DEPRECATED message. + * + * To utilitize this function pass the results to trigger_error() like so: + * + * @code + * $message = islandora_deprecated('7.x-1.1', t('Use more cowbell.')); + * trigger_error($message, E_USER_DEPRECATED); + * @endcode + * + * @param string $release + * The release the calling function was depreciated in. + * @param string $solution + * A message describing an alternative solution to the deprecated function. + * It's assumed to be already passed though the t() function. + * + * @return string + * The deprecated message. + */ +function islandora_deprecated($release, $solution = NULL) { + $bt = debug_backtrace(); + assert($bt[0]['function'] == __FUNCTION__); + $function = $bt[1]['function']; + $message = t('@function() has been deprecated. As of @release, please update your code before the next release.', array( + '@function' => $function, + '@release' => $release, + )); + if (isset($solution)) { + $message .= "
\n" . $solution; + } + return $message; +} From 5fac157cfcb08b9a647c6c70c8ec5ae75baa009c Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Tue, 30 Apr 2013 18:37:34 +0200 Subject: [PATCH 2/4] Appease the Travis God! The one true build master! May my code be clean, and follow the law's of "standard". May it support internationalization for Travis includes all! May it not contain copy pasta for it is soggy. Travis be praised! --- includes/utilities.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index aac770e2..57bf03ba 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -825,7 +825,7 @@ function islandora_content_model_select_table_form_element($drupal_variable, $de * * @code * $message = islandora_deprecated('7.x-1.1', t('Use more cowbell.')); - * trigger_error($message, E_USER_DEPRECATED); + * trigger_error(check_plain($message), E_USER_DEPRECATED); * @endcode * * @param string $release From 8b0b3203384e8da583571c0e2ec9bbe2fcc4b76a Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Tue, 30 Apr 2013 21:46:41 +0200 Subject: [PATCH 3/4] Configuration options now accept multiple objects. Configuration no longer requires validation. Added Convience method for determining if the ingest forms can be rendered. --- includes/ingest.form.inc | 121 +++++++++++++++++++++------------------ includes/utilities.inc | 4 +- 2 files changed, 68 insertions(+), 57 deletions(-) diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index 5c9e3e55..1d19babe 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -5,6 +5,27 @@ * Defines the multi-page ingest form and any relevant hooks and functions. */ +require_once 'utilities.inc'; + +/** + * Checks if the given configuration can be used to display the ingest form. + * + * @param array $configuration + * The list of key/value pairs of configuration. + * + * @return bool + * TRUE if the give configuration defines one or more form steps, FALSE + * otherwise. + */ +function islandora_ingest_can_display_ingest_form(array $configuration) { + $form_state = array(); + islandora_ingest_form_init_form_state_storage($form_state, $configuration); + $form_steps = islandora_ingest_form_get_form_steps($form_state); + // Forget the stubbed steps for the remainder of this request. + drupal_static_reset('islandora_ingest_form_get_steps'); + return count($form_steps) > 0; +} + /** * Ingest form build function. * @@ -44,26 +65,6 @@ function islandora_ingest_form(array $form, array &$form_state, array $configura } } -/** - * Validates the given ingest configuration. - * - * At the moment it only requires that models are present. - * - * @todo Add hook for manipulating/validating the configuration. - * - * @see islandora_ingest_form() - * - * @throws InvalidArgumentException - * - * @param array $configuration - * The key value pairs that are used to build the multi-paged ingest process. - */ -function islandora_ingest_form_validate_configuration(array $configuration) { - if (empty($configuration['models'])) { - throw new InvalidArgumentException('Ingest configuration not vaild, no models were given'); - } -} - /** * Initializes the form_state storage for use in the ingest multi-page forms. * @@ -75,12 +76,15 @@ function islandora_ingest_form_validate_configuration(array $configuration) { */ function islandora_ingest_form_init_form_state_storage(array &$form_state, array $configuration) { if (empty($form_state['islandora'])) { - // Validate the configuration before we use it. - islandora_ingest_form_validate_configuration($configuration); - $object = islandora_ingest_form_prepare_new_object($configuration); + $objects = isset($configuration['objects']) ? $configuration['objects'] : array(); + if (empty($objects)) { + $objects[] = islandora_ingest_form_prepare_new_object($configuration); + } + // No need to persist the 'objects' within the configuration. + unset($configuration['objects']); $form_state['islandora'] = array( 'step_id' => NULL, - 'objects' => array($object), + 'objects' => $objects, 'shared_storage' => $configuration, 'step_storage' => array(), ); @@ -130,8 +134,9 @@ function islandora_ingest_form_get_last_step_id(array &$form_state) { * The new object. */ function islandora_ingest_form_prepare_new_object(array $configuration) { - module_load_include('inc', 'islandora', 'includes/utilities'); if (empty($configuration['object'])) { + $message = islandora_deprecated('Please use "objects" as the default ingest form configuration property.'); + trigger_error(check_plain($message), E_USER_DEPRECATED); // ID is more specific than namespace so it will take precedence. $id = isset($configuration['namespace']) ? $configuration['namespace'] : 'islandora'; $id = isset($configuration['id']) ? $configuration['id'] : $id; @@ -307,35 +312,6 @@ function islandora_ingest_form_decrement_step(array &$form_state) { } } -/** - * Build a list of steps given only configuration. - * - * XXX: This is used to give an indication of whether there are any steps for a - * given configuration. - * - * @param array $configuration - * The list of key/value pairs of configuration. - */ -function islandora_ingest_get_approximate_steps(array $configuration) { - try { - // @todo, we need to expand the configuration before we can validate it? - // I think this need some thinking. - islandora_ingest_form_validate_configuration($configuration); - } - catch (InvalidArgumentException $e) { - // Don't log or display exception. - return array(); - } - $stubbed_form_state = array( - 'islandora' => array( - 'shared_storage' => $configuration, - ), - ); - $steps = islandora_ingest_form_get_steps($stubbed_form_state); - drupal_static_reset('islandora_ingest_form_get_steps'); - return $steps; -} - /** * Executes the current step. * @@ -826,7 +802,6 @@ function islandora_ingest_form_load_include(array &$form_state) { * of ISLANDORA_INGEST_STEP_HOOK. */ function islandora_ingest_form_get_steps(array &$form_state) { - module_load_include('inc', 'islandora', 'includes/utilities'); $steps = &drupal_static(__FUNCTION__); if (isset($steps)) { return $steps; @@ -854,3 +829,39 @@ function islandora_ingest_form_get_steps(array &$form_state) { uasort($steps, 'drupal_sort_weight'); return $steps; } + +/** + * Filter the ingest steps to only steps of type 'form'. + * + * @param array $form_state + * The Drupal form state. + * + * @return array + * The list of sorted ingest form steps as defined by all implementers + * of ISLANDORA_INGEST_STEP_HOOK. + */ +function islandora_ingest_form_get_form_steps(array &$form_state) { + $steps = islandora_ingest_form_get_steps($form_state); + $form_step_filter = function($o) { + return $o['type'] == 'form'; + }; + return array_filter($steps, $form_step_filter); +} + +/** + * Filter the ingest steps to only steps of type 'form'. + * + * @param array $form_state + * The Drupal form state. + * + * @return array + * The list of sorted ingest callback steps as defined by all implementers + * of ISLANDORA_INGEST_STEP_HOOK. + */ +function islandora_ingest_form_get_callback_steps(array &$form_state) { + $steps = islandora_ingest_form_get_steps($form_state); + $callback_step_filter = function($o) { + return $o['type'] == 'callback'; + }; + return array_filter($steps, $callback_step_filter); +} diff --git a/includes/utilities.inc b/includes/utilities.inc index 57bf03ba..751b85cc 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -824,8 +824,8 @@ function islandora_content_model_select_table_form_element($drupal_variable, $de * To utilitize this function pass the results to trigger_error() like so: * * @code - * $message = islandora_deprecated('7.x-1.1', t('Use more cowbell.')); - * trigger_error(check_plain($message), E_USER_DEPRECATED); + * $message = islandora_deprecated('7.x-1.1', t('Use more cowbell.')) + * trigger_error(check_plain($message), E_USER_DEPRECATED) * @endcode * * @param string $release From da9c62003e801f65de93f4706ba57f09437ddc1b Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Wed, 1 May 2013 17:13:02 +0200 Subject: [PATCH 4/4] Coding standards compliance? --- includes/ingest.form.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index 1d19babe..0a9ce6e6 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -5,8 +5,6 @@ * Defines the multi-page ingest form and any relevant hooks and functions. */ -require_once 'utilities.inc'; - /** * Checks if the given configuration can be used to display the ingest form. * @@ -134,6 +132,7 @@ function islandora_ingest_form_get_last_step_id(array &$form_state) { * The new object. */ function islandora_ingest_form_prepare_new_object(array $configuration) { + module_load_include('inc', 'islandora', 'includes/utilities'); if (empty($configuration['object'])) { $message = islandora_deprecated('Please use "objects" as the default ingest form configuration property.'); trigger_error(check_plain($message), E_USER_DEPRECATED); @@ -802,6 +801,7 @@ function islandora_ingest_form_load_include(array &$form_state) { * of ISLANDORA_INGEST_STEP_HOOK. */ function islandora_ingest_form_get_steps(array &$form_state) { + module_load_include('inc', 'islandora', 'includes/utilities'); $steps = &drupal_static(__FUNCTION__); if (isset($steps)) { return $steps;