Browse Source

Make control group selection optional.

pull/101/head
Adam Vessey 13 years ago
parent
commit
7bc755f231
  1. 25
      fedora_repository.module
  2. 50
      formClass.inc

25
fedora_repository.module

@ -388,7 +388,7 @@ function add_stream_form_submit($form, &$form_state) {
try {
$item = new Fedora_Item($pid);
$item->add_datastream_from_url($form_state['storage']['stream_url'], $dsid, $dsLabel, $form_state['storage']['ds_mimetype'], $form_state['values']['control_group']);
$item->add_datastream_from_url($form_state['storage']['stream_url'], $dsid, $dsLabel, $form_state['storage']['ds_mimetype'], $form_state['storage']['control_group']);
if ($file = $form_state['values']['add-stream-file-location']) {
$object_helper = new ObjectHelper();
@ -450,14 +450,12 @@ function add_stream_form_validate($form, &$form_state) {
// 'file_validate_image_resolution' => array('85x85'),
// 'file_validate_size' => array(30 * 1024),
);
$mimetype = new MimeClass();
$controlGroup = $form_state['values']['control_group'];
if (in_array($controlGroup, array('X', 'M')) && ($fileObject = file_save_upload('add-stream-file-location', $validators)) !== 0) {
$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)) {
// Move the uploaded file to Drupal's files directory.
file_move($fileObject->filepath, 0, 'FILE_EXISTS_RENAME');
$form_state['values']['add-stream-file-location'] = $fileObject->filepath;
$form_state['storage']['ds_mimetype'] = $mimetype->getType($fileObject->filepath);
$file_basename = basename($fileObject->filepath);
$file_directory = dirname($fileObject->filepath);
@ -466,14 +464,25 @@ function add_stream_form_validate($form, &$form_state) {
'absolute' => TRUE,
));
}
elseif (in_array($controlGroup, array('M', 'R', 'E')) && ($ref = $form_state['values']['ds_reference'])) {
$form_state['storage']['ds_mimetype'] = $mimetype->getType($ref);
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'];
}
else {
form_set_error('', t('No file given when "X" or "M", or no reference given when "M", "R" or "E".'));
}
$mimeClass = new MimeClass();
$mimetype = $form_state['storage']['ds_mimetype'] = $mimeClass->getType($form_state['storage']['stream_url']);
if (!$controlGroup) {
if ($mimetype == 'text/xml') {
$form_state['storage']['control_group'] = 'X';
}
else {
$form_state['storage']['control_group'] = 'M';
}
}
// TODO: Add error checking here.
$form_state['rebuild'] = FALSE;
}

50
formClass.inc

@ -331,6 +331,13 @@ class formClass {
'#options' => array(ObjectHelper::$DISPLAY_ALWAYS => t('Always'), ObjectHelper::$DISPLAY_NEVER => t('Never'), ObjectHelper::$DISPLAY_NO_MODEL_OUTPUT => t('Only if no Content Model display output.')),
'#description' => t('Determines when to display the list of objects when viewing a collection page.'),
);
$form['advanced']['fedora_control_group_control_during_ingest'] = array(
'#type' => 'checkbox',
'#title' => t('Allow control groups select in datastream ingest'),
'#description' => t('Whether or not we should allow the user to select which control group to ingest a stream as, or to follow the old paradigm--to add stream IDed as XML as inline, and everything else as managed.'),
'#default_value' => variable_get('fedora_control_group_control_during_ingest', FALSE),
);
//Export functionality
$form['advanced']['module']['export_area'] = array(
@ -685,12 +692,16 @@ class formClass {
// '#required'=>'TRUE',
'#description' => t('The file to upload. (Only for Managed and Inline)')
);
$form['fieldset']['ds_reference'] = array(
'#type' => 'textfield',
'#title' => t('Datastream reference'),
'#size' => 48,
'#description' => t('A URL reference to resolve for the contents of the datastream. (Required for External and Redirect, but will still work for Managed and Inline.)'),
);
if (variable_get('fedora_control_group_control_during_ingest', FALSE)) {
$form['fieldset']['ds_reference'] = array(
'#type' => 'textfield',
'#title' => t('Datastream reference'),
'#size' => 48,
'#description' => t('A URL reference to resolve for the contents of the datastream. (Required for External and Redirect, but will still work for Managed and Inline.)'),
);
}
$form['#redirect'] = "fedora/repository/$pid/";
$form['fieldset']['submit'] = array(
'#type' => 'submit',
@ -716,18 +727,21 @@ class formClass {
'#weight' => -1,
);
}
$form['fieldset']['control_group'] = array(
'#type' => 'select',
'#title' => t('Control group'),
'#options' => array(
'X' => t('Inline XML'),
'M' => t('Managed datastream'),
'E' => t('Externally Referenced/managed datastream'),
'R' => t('Redirect datastream'),
),
'#description' => t('The manner in which the datastream will be stored. "Inline XML" must be XML and will be placed directly into the FOXML for the object. "Managed" datastreams are made to live on the filesystem as discrete files in the Fedora data directory. Both "Redirect" and "External" streams are URL references; the difference being the redirect stream instruct clients to perform an HTTP redirect, such that the data does not pass though Fedora (useful for streaming). External streams are mediated (by which I mean loaded and streamed from) the Fedora server.'),
'#weight' => 0,
);
if (variable_get('fedora_control_group_control_during_ingest', FALSE)) {
$form['fieldset']['control_group'] = array(
'#type' => 'select',
'#title' => t('Control group'),
'#options' => array(
'X' => t('Inline XML'),
'M' => t('Managed datastream'),
'E' => t('Externally Referenced/managed datastream'),
'R' => t('Redirect datastream'),
),
'#description' => t('The manner in which the datastream will be stored. "Inline XML" must be XML and will be placed directly into the FOXML for the object. "Managed" datastreams are made to live on the filesystem as discrete files in the Fedora data directory. Both "Redirect" and "External" streams are URL references; the difference being the redirect stream instruct clients to perform an HTTP redirect, such that the data does not pass though Fedora (useful for streaming). External streams are mediated (by which I mean loaded and streamed from) the Fedora server.'),
'#weight' => 0,
);
}
return $form;
}

Loading…
Cancel
Save