Skip to content

Commit

Permalink
Configured the viewer to allow file upload fields in the ingest form.
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelgbanks committed Sep 9, 2011
1 parent 84dd072 commit ac9ae4c
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions content_model_viewer.module
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,38 @@ function content_model_viewer_ingest_metadata_form_validate(array &$form, array
$form_state['rebuild'] = TRUE;
}
else {
if (!empty($_FILES['files']['name']['ingest-file-location'])) {
$file = file_save_upload('ingest-file-location');
file_move($file->filepath, 0, 'FILE_EXISTS_RENAME');
$form_state['values']['ingest-file-location'] = $file->filepath;
}
if (isset($form_state['values']['ingest-file-location']) && file_exists($form_state['values']['ingest-file-location'])) {
module_load_include('inc', 'fedora_repository', 'ContentModel');
module_load_include('inc', 'fedora_repository', 'MimeClass');
$file = $form_state['values']['ingest-file-location'];
$content_model_pid = ContentModel::getPidFromIdentifier($form_state['values']['models']);
$content_model_pid;
$content_model_dsid = ContentModel::getDSIDFromIdentifier($form_state['values']['models']);
if (($content_model = ContentModel::loadFromModel($content_model_pid, $content_model_dsid)) !== FALSE) {
$allowed_mime_types = $content_model->getMimetypes();
$mimetype = new MimeClass();
$format = $mimetype->getType($file);
if (!empty($file)) {
if (!in_array($format, $allowed_mime_types)) {
form_set_error('ingest-file-location', t('The uploaded file\'s mimetype (' . $format . ') is not associated with this Content Model. The allowed types are ' .
implode(' ', $allowed_mime_types)));
file_delete($file);
return;
}
elseif (!$content_model->execIngestRules($file, $format)) {
drupal_set_message(t('Error following Content Model Rules'), 'error');
foreach (ContentModel::$errors as $error) {
drupal_set_message($error, 'error');
}
}
}
}
}
module_load_include('inc', 'xml_form_api', 'XMLForm');
$xml_form = new XMLForm($form_state);
$xml_form->validate($form, $form_state);
Expand Down

0 comments on commit ac9ae4c

Please sign in to comment.