diff --git a/ContentModel.inc b/ContentModel.inc index 381fa9ac..5ed33d59 100644 --- a/ContentModel.inc +++ b/ContentModel.inc @@ -1372,9 +1372,10 @@ class ContentModel extends XMLDatastream { * Executes the form handler from the element of . * * @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; } } diff --git a/fedora_repository.module b/fedora_repository.module index 093bdb2d..abd323c0 100644 --- a/fedora_repository.module +++ b/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 diff --git a/form_elements/includes/people.inc b/form_elements/includes/people.inc index 9d44055f..f19bf9b8 100644 --- a/form_elements/includes/people.inc +++ b/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 '
';   echo $_POST['form_build_id']."\n"; var_dump($form_state);   echo '
'; $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 '
'; echo $form_state['clicked_button']['#parents'][2]; var_dump($form_state['storage']['people']); echo'
'; $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; } diff --git a/form_elements/islandora_form_elements.module b/form_elements/islandora_form_elements.module index 75214db0..e174693b 100644 --- a/form_elements/islandora_form_elements.module +++ b/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'] = '
'; $element['#suffix'] = '
'; @@ -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 '
'; var_dump($json); echo '
'; drupal_set_message(ob_get_contents()); ob_end_clean(); + switch ($json->type) { diff --git a/plugins/ModsFormBuilder.inc b/plugins/ModsFormBuilder.inc index 47dab34c..d3907d38 100644 --- a/plugins/ModsFormBuilder.inc +++ b/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