function tripal_get_importer_form_submit
3.x tripal.importer.inc | tripal_get_importer_form_submit($form, &$form_state) |
Submit function for the tripal_get_importer_form form().
File
- tripal/
includes/ tripal.importer.inc, line 163
Code
function tripal_get_importer_form_submit($form, &$form_state) {
global $user;
$run_args = $form_state['values'];
$class = $form_state['values']['importer_class'];
tripal_load_include_importer_class($class);
// Remove the file_local and file_upload args. We'll add in a new
// full file path and the fid instead.
unset($run_args['file_local']);
unset($run_args['file_upload']);
unset($run_args['file_upload_existing']);
unset($run_args['form_build_id']);
unset($run_args['form_token']);
unset($run_args['form_id']);
unset($run_args['op']);
unset($run_args['button']);
$file_local = NULL;
$file_upload = NULL;
$file_remote = NULL;
$file_existing = NULL;
// Get the form values for the file.
if (array_key_exists('file_local', $class::$methods) and $class::$methods['file_local'] == TRUE) {
$file_local = trim($form_state['values']['file_local']);
}
if (array_key_exists('file_upload', $class::$methods) and $class::$methods['file_upload'] == TRUE) {
$file_upload = trim($form_state['values']['file_upload']);
if (array_key_exists('file_upload_existing', $form_state['values']) and $form_state['values']['file_upload_existing']) {
$file_existing = trim($form_state['values']['file_upload_existing']);
}
}
if (array_key_exists('file_remote', $class::$methods) and $class::$methods['file_remote'] == TRUE) {
$file_remote = trim($form_state['values']['file_remote']);
}
// Sumbit a job for this loader.
$fname = '';
$fid = NULL;
$file_details = array();
if ($file_existing) {
$file_details['fid'] = $file_existing;
}
elseif ($file_local) {
$fname = preg_replace("/.*\/(.*)/", "$1", $file_local);
$file_details['file_local'] = $file_local;
}
elseif ($file_upload) {
$file_details['fid'] = $file_upload;
}
elseif ($file_remote) {
$file_details['file_remote'] = $file_remote;
}
try {
// Now allow the loader to do its own submit if needed.
$importer = new $class();
$importer->formSubmit($form, $form_state);
// If the formSubmit made changes to the $form_state we need to update the
// $run_args info.
if ($run_args !== $form_state['values']) {
$run_args = $form_state['values'];
}
// If the importer wants to rebuild the form for some reason then let's
// not add a job.
if (array_key_exists('rebuild', $form_state) and $form_state['rebuild'] == TRUE) {
return;
}
$importer->create($run_args, $file_details);
$importer->submitJob();
}
catch (Exception $e) {
drupal_set_message('Cannot submit import: ' . $e->getMessage(), 'error');
}
}