Browse Source

Fixed a bug with the entity editor keeping data from one ingest to the next. Fixed it by having the form handler plugin clear the ['people']. In order to do this, I needed to add & to the parameters list of the form handler.

pull/105/head
mroy 14 years ago
parent
commit
415c950bae
  1. 5
      ContentModel.inc
  2. 2
      fedora_repository.module
  3. 25
      form_elements/includes/people.inc
  4. 5
      form_elements/islandora_form_elements.module
  5. 6
      plugins/ModsFormBuilder.inc

5
ContentModel.inc

@ -1372,9 +1372,10 @@ class ContentModel extends XMLDatastream {
* Executes the form handler from the <form_builder_method> element of <ingest_form>.
*
* @param &$formData
* @param &$form_state
* @return boolean $success
*/
public function execFormHandler(&$data) {
public function execFormHandler(&$data,&$form_state) {
$ret = FALSE;
if ($this->validate()) {
$method =$this->xml->getElementsByTagName('ingest_form')->item(0)->getElementsByTagName('form_builder_method')->item(0);
@ -1396,7 +1397,7 @@ class ContentModel extends XMLDatastream {
self::$errors[] = 'Execute Form Handler: method \''. $className .'->'. $methodName .'\' does not exist.';
}
else {
$class->$methodName($data);
$class->$methodName($data,$form_state);
$ret = TRUE;
}
}

2
fedora_repository.module

@ -144,7 +144,7 @@ function fedora_repository_ingest_form_submit($form, &$form_state) {
$form_state['values']['content_model_pid'] = $contentModelPid;
$form_state['values']['relationship'] = $relationship;
$err = (!$cm->execFormHandler($form_state['values']));
$err = (!$cm->execFormHandler($form_state['values'],$form_state));
$_SESSION['fedora_ingest_files'] = ''; //empty this variable

25
form_elements/includes/people.inc

@ -40,12 +40,15 @@ function _ife_find_people_element($form, &$keys = array()) {
}
function ife_people_ahah() {
if (!isset($_POST['form_build_id']))
return;
$form_state = array('storage' => NULL, 'submitted' => FALSE);
$form_build_id = $_POST['form_build_id'];
$form = form_get_cache($form_build_id, $form_state);
$args = $form['#parameters'];
$form_id = array_shift($args);
$form['#post'] = $_POST;
@ -57,10 +60,11 @@ function ife_people_ahah() {
$form['#post'] = $_POST;
drupal_process_form($form_id, $form, $form_state);
// ob_start(); echo '<pre>'; echo $_POST['form_build_id']."\n"; var_dump($form_state); echo '</pre>'; $dump = ob_get_contents(); ob_end_clean();
$form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
$qt_form = _ife_find_people_element($form);
// ob_start(); echo '<pre>'; echo $form_state['clicked_button']['#parents'][2]; var_dump($form_state['storage']['people']); echo'</pre>'; $dump = ob_get_contents(); ob_end_clean();
unset($qt_form['#prefix'], $qt_form['#suffix']); // Prevent duplicate wrappers.
$javascript = drupal_add_js(NULL, NULL, 'header');
@ -105,7 +109,7 @@ function ife_remove_person_submit($form, &$form_state) {
unset($form_state['submit_handlers']);
form_execute_handlers('submit', $form, $form_state);
$form_state['storage']['people'] = $people;
$form_state['rebuild'] = TRUE;
//$form_state['rebuild'] = TRUE;
}
@ -117,6 +121,7 @@ function ife_add_person_submit($form, &$form_state) {
$keys = array();
$qt_form = _ife_find_people_element($form, $keys);
$peopleVals = &$form_state['values'];
while (count($keys) > 0) {
$key = array_pop($keys);
if (isset($peopleVals[$key])) {
@ -129,12 +134,16 @@ function ife_add_person_submit($form, &$form_state) {
foreach ($peopleVals['people'] as $val) {
$people[] = $val;
}
$people[] = array('name' => '', 'date'=>'', 'role' => '', 'subject' => '');
//only add new person if we are not adding from repository.
if (!isset($form_state['post']['add_from_repository']) || trim($form_state['post']['add_from_repository']) == '') {
$people[] = array('name' => '', 'date'=>'', 'role' => '', 'subject' => '');
}
unset($form_state['submit_handlers']);
form_execute_handlers('submit', $form, $form_state);
$form_state['storage']['people'] = $people;
$form_state['rebuild'] = TRUE;
// $form_state['rebuild'] = TRUE;
}
@ -147,12 +156,14 @@ function ife_add_org_submit($form, &$form_state) {
$keys = array();
$qt_form = _ife_find_people_element($form, $keys);
$peopleVals = &$form_state['values'];
while (count($keys) > 0) {
$key = array_pop($keys);
if (isset($peopleVals[$key])) {
$peopleVals = &$peopleVals[$key];
}
}
if (!is_array($peopleVals['people']))
$peopleVals['people'] = array();
@ -164,7 +175,7 @@ function ife_add_org_submit($form, &$form_state) {
unset($form_state['submit_handlers']);
form_execute_handlers('submit', $form, $form_state);
$form_state['storage']['people'] = $people;
$form_state['rebuild'] = TRUE;
//$form_state['rebuild'] = TRUE;
}
@ -194,7 +205,7 @@ function ife_add_conf_submit($form, &$form_state) {
unset($form_state['submit_handlers']);
form_execute_handlers('submit', $form, $form_state);
$form_state['storage']['people'] = $people;
$form_state['rebuild'] = TRUE;
//$form_state['rebuild'] = TRUE;
}

5
form_elements/islandora_form_elements.module

@ -129,7 +129,7 @@ function ife_fieldset_children_has_value($el)
function ife_people_process($element,$edit,&$form_state)
{
$element['#tree'] = TRUE;
$element['#prefix'] = '<div class="clear-block" id="ife-people-wrapper">';
$element['#suffix'] = '</div>';
@ -141,7 +141,6 @@ function ife_people_process($element,$edit,&$form_state)
'#theme' => 'people_items',
);
if (isset($form_state['post'][$element['#name']]['add_from_repository']) && trim($form_state['post'][$element['#name']]['add_from_repository']) != '') {
$people= array();
@ -156,7 +155,7 @@ function ife_people_process($element,$edit,&$form_state)
$json = json_decode($form_state['post'][$element['#name']]['add_from_repository']);
$person=array();
// ob_start(); echo '<pre>'; var_dump($json); echo '</pre>'; drupal_set_message(ob_get_contents()); ob_end_clean();
switch ($json->type)
{

6
plugins/ModsFormBuilder.inc

@ -231,10 +231,12 @@ class ModsFormBuilder extends FormBuilder {
}
function handleModsForm($form_values) {
function handleModsForm(&$form_values,&$form_state) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'CollectionPolicy');
$form_state['storage']['people']=NULL; //clears out old entities for the next run of the formbuilder.
$dom = new DomDocument("1.0", "UTF-8");
$dom->formatOutput = TRUE;
$pid=$form_values['pid'];
@ -272,7 +274,7 @@ class ModsFormBuilder extends FormBuilder {
// header('Content-type: application/xml');
// echo $dom->saveXML(); exit();
try {
$object = Fedora_Item::ingest_from_FOXML($dom);
//for some reason, ingest_from_FOXML does not generate a JMS message

Loading…
Cancel
Save