Browse Source

Fix stream addition with language prefixes.

pull/126/head
Adam Vessey 13 years ago
parent
commit
933d0bc598
  1. 23
      fedora_repository.module

23
fedora_repository.module

@ -384,7 +384,7 @@ function add_stream_form_submit($form, &$form_state) {
$pid = $form_state['values']['pid']; $pid = $form_state['values']['pid'];
$dsid = $form_state['values']['stream_id']; $dsid = $form_state['values']['stream_id'];
$dsLabel = $form_state['values']['stream_label'] . substr($file, strrpos($file, '.')); // Add the file extention to the end of the label.; $dsLabel = $form_state['values']['stream_label'] . substr($form_state['storage']['stream_url'], strrpos($form_state['storage']['stream_url'], '.')); // Add the file extention to the end of the label.;
try { try {
$item = new Fedora_Item($pid); $item = new Fedora_Item($pid);
@ -400,6 +400,7 @@ function add_stream_form_submit($form, &$form_state) {
drupal_set_message(t('@message', array('@message' => check_plain($e->getMessage()))), 'error'); drupal_set_message(t('@message', array('@message' => check_plain($e->getMessage()))), 'error');
return; return;
} }
unset($form_state['storage']); //Using storage; need to unset it for forms to work properly...
$form_state['rebuild'] = TRUE; $form_state['rebuild'] = TRUE;
} }
@ -452,17 +453,13 @@ function add_stream_form_validate($form, &$form_state) {
); );
$controlGroup = $form_state['storage']['control_group'] = $form_state['values']['control_group']; $controlGroup = $form_state['storage']['control_group'] = $form_state['values']['control_group'];
if ((($controlGroup && in_array($controlGroup, array('X', 'M'))) || !$controlGroup) && (($fileObject = file_save_upload('add-stream-file-location', $validators)) !== 0)) { if ((($controlGroup && in_array($controlGroup, array('X', 'M'))) || !$controlGroup) && (($fileObject = file_save_upload('add-stream-file-location', $validators)))) {
// Move the uploaded file to Drupal's files directory. // Move the uploaded file to Drupal's files directory.
file_move($fileObject->filepath, 0, 'FILE_EXISTS_RENAME'); $file_path = $fileObject->filepath;
$form_state['values']['add-stream-file-location'] = $fileObject->filepath; file_move($file_path, 0, FILE_EXISTS_RENAME);
$form_state['values']['add-stream-file-location'] = $file_path;
$file_basename = basename($fileObject->filepath);
$file_directory = dirname($fileObject->filepath);
$form_state['storage']['stream_url'] = url($file_directory . '/' . drupal_urlencode($file_basename), array( $form_state['storage']['stream_url'] = file_create_url($file_path);
'absolute' => TRUE,
));
} }
elseif ($controlGroup && in_array($controlGroup, array('M', 'R', 'E')) && ($ref = $form_state['values']['ds_reference'])) { elseif ($controlGroup && in_array($controlGroup, array('M', 'R', 'E')) && ($ref = $form_state['values']['ds_reference'])) {
$form_state['storage']['stream_url'] = $form_state['values']['ds_reference']; $form_state['storage']['stream_url'] = $form_state['values']['ds_reference'];
@ -726,6 +723,9 @@ function fedora_repository_replace_stream_form_validate($form, &$form_state) {
// set files to form_state, to process when form is submitted // set files to form_state, to process when form is submitted
$form_state['values']['file'] = $file; $form_state['values']['file'] = $file;
} }
elseif (!$form_state['values']['ds_reference']) {
form_set_error('', 'Need either a file or a reference!');
}
} }
/** /**
@ -742,7 +742,7 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) {
$dsLabel = $form_state['values']['dsLabel']; $dsLabel = $form_state['values']['dsLabel'];
$streamUrl = ($file !== NULL) ? $streamUrl = ($file !== NULL) ?
$file->filepath: file_create_url($file->filepath):
url($form_state['values']['reference'], array('absolute' => TRUE)); url($form_state['values']['reference'], array('absolute' => TRUE));
// Remove the original file extension from the label and add the new one // Remove the original file extension from the label and add the new one
@ -758,6 +758,7 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) {
$item = new Fedora_Item($pid); $item = new Fedora_Item($pid);
$item->modify_datastream($streamUrl, $dsid, $dsLabel, $dformat); $item->modify_datastream($streamUrl, $dsid, $dsLabel, $dformat);
unset($form_state['storage']);
$form_state['redirect'] = 'fedora/repository/' . $pid; $form_state['redirect'] = 'fedora/repository/' . $pid;
} }

Loading…
Cancel
Save