Browse Source

Configuration options now accept multiple objects.

Configuration no longer requires validation.
Added Convience method for determining if the ingest forms can be rendered.
pull/325/head
Nigel Banks 12 years ago
parent
commit
8b0b320338
  1. 121
      includes/ingest.form.inc
  2. 4
      includes/utilities.inc

121
includes/ingest.form.inc

@ -5,6 +5,27 @@
* Defines the multi-page ingest form and any relevant hooks and functions. * 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. * 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. * 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) { function islandora_ingest_form_init_form_state_storage(array &$form_state, array $configuration) {
if (empty($form_state['islandora'])) { if (empty($form_state['islandora'])) {
// Validate the configuration before we use it. $objects = isset($configuration['objects']) ? $configuration['objects'] : array();
islandora_ingest_form_validate_configuration($configuration); if (empty($objects)) {
$object = islandora_ingest_form_prepare_new_object($configuration); $objects[] = islandora_ingest_form_prepare_new_object($configuration);
}
// No need to persist the 'objects' within the configuration.
unset($configuration['objects']);
$form_state['islandora'] = array( $form_state['islandora'] = array(
'step_id' => NULL, 'step_id' => NULL,
'objects' => array($object), 'objects' => $objects,
'shared_storage' => $configuration, 'shared_storage' => $configuration,
'step_storage' => array(), 'step_storage' => array(),
); );
@ -130,8 +134,9 @@ function islandora_ingest_form_get_last_step_id(array &$form_state) {
* The new object. * The new object.
*/ */
function islandora_ingest_form_prepare_new_object(array $configuration) { function islandora_ingest_form_prepare_new_object(array $configuration) {
module_load_include('inc', 'islandora', 'includes/utilities');
if (empty($configuration['object'])) { 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 is more specific than namespace so it will take precedence.
$id = isset($configuration['namespace']) ? $configuration['namespace'] : 'islandora'; $id = isset($configuration['namespace']) ? $configuration['namespace'] : 'islandora';
$id = isset($configuration['id']) ? $configuration['id'] : $id; $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. * Executes the current step.
* *
@ -826,7 +802,6 @@ function islandora_ingest_form_load_include(array &$form_state) {
* of ISLANDORA_INGEST_STEP_HOOK. * of ISLANDORA_INGEST_STEP_HOOK.
*/ */
function islandora_ingest_form_get_steps(array &$form_state) { function islandora_ingest_form_get_steps(array &$form_state) {
module_load_include('inc', 'islandora', 'includes/utilities');
$steps = &drupal_static(__FUNCTION__); $steps = &drupal_static(__FUNCTION__);
if (isset($steps)) { if (isset($steps)) {
return $steps; return $steps;
@ -854,3 +829,39 @@ function islandora_ingest_form_get_steps(array &$form_state) {
uasort($steps, 'drupal_sort_weight'); uasort($steps, 'drupal_sort_weight');
return $steps; 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);
}

4
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: * To utilitize this function pass the results to trigger_error() like so:
* *
* @code * @code
* $message = islandora_deprecated('7.x-1.1', t('Use more cowbell.')); * $message = islandora_deprecated('7.x-1.1', t('Use more cowbell.'))
* trigger_error(check_plain($message), E_USER_DEPRECATED); * trigger_error(check_plain($message), E_USER_DEPRECATED)
* @endcode * @endcode
* *
* @param string $release * @param string $release

Loading…
Cancel
Save