Browse Source

Merge pull request #325 from nigelgbanks/7.x-ingest-without-xml-forms

7.x ingest without xml forms
pull/327/head
Adam 12 years ago
parent
commit
e701b28619
  1. 117
      includes/ingest.form.inc
  2. 33
      includes/utilities.inc

117
includes/ingest.form.inc

@ -5,6 +5,25 @@
* Defines the multi-page ingest form and any relevant hooks and functions. * Defines the multi-page ingest form and any relevant hooks and functions.
*/ */
/**
* 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 +63,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 +74,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(),
); );
@ -132,6 +134,8 @@ function islandora_ingest_form_get_last_step_id(array &$form_state) {
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'); 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 +311,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.
* *
@ -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);
}

33
includes/utilities.inc

@ -817,3 +817,36 @@ function islandora_content_model_select_table_form_element($drupal_variable, $de
return $element; 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(check_plain($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 .= "<br/>\n" . $solution;
}
return $message;
}

Loading…
Cancel
Save