Browse Source

Allowed user to remove primary cross reference

Chun-Huai Cheng 9 years ago
parent
commit
ac22f04507

+ 3 - 3
tripal_entities/includes/tripal_entities.field_storage.inc

@@ -32,7 +32,7 @@ function tripal_entities_field_storage_write($entity_type, $entity, $op, $fields
     $residues = $field_vals['feature__residues'];
     $field_vals['feature__md5checksum'] = $field_vals['feature__md5checksum'] ? md5($residues) : NULL;
   }
-dpm($field_vals);
+
   switch ($op) {
     case FIELD_STORAGE_INSERT:
       // Use the cvterm_id to look up tables where this term is used
@@ -79,7 +79,7 @@ dpm($field_vals);
  */
 function tripal_entities_field_storage_write_recursive($entity_type, $entity,
    $op, $field_vals, $tablename, $type_field = NULL, $record_id = NULL, $depth = 0) {
-  dpm($tablename);
+
   // Intialize the values array and $record_id;
   $values = array();
 
@@ -112,7 +112,7 @@ function tripal_entities_field_storage_write_recursive($entity_type, $entity,
       $fk_val = array_key_exists($fk_field_name, $field_vals) ? $field_vals[$fk_field_name] : NULL;
       $fk_val = tripal_entities_field_storage_write_recursive($entity_type,
         $entity, $op, $field_vals, $fk_table, NULL, $fk_val, $depth + 1);
-      if (!isset($fk_val) or $fk_value != '') {
+      if (!isset($fk_val) or $fk_val != '') {
         $values[$local_id] = $fk_val;
       }
     }

+ 9 - 1
tripal_entities/includes/tripal_entities.fields.inc

@@ -312,6 +312,14 @@ function tripal_entities_primary_dbxref_widget_validate($element, &$form_state)
   if (count($db_id) > 0 and count($accession) == 0) {
     form_set_error(implode('][', $element ['#parents']) . '][0][dbxref__accession', t("A database and the accession must both be provided for the primary cross reference."));
   }
+  
+  // If user did not select a database, we want to remove dbxref_id from the 
+  // feature table but keep the dbxref record
+  if (count($db_id) == 0) {
+    foreach ($form_state['values'][$field_name] as $langcode => $items) {
+      $form_state['values']['feature__dbxref_id'][$langcode][0]['value'][0]['feature__dbxref_id'] = '__NULL__';
+    }
+  }
 }
 /**
  * Callback function for validating the tripal_entities_md5checksum_checkbox_widget.
@@ -361,4 +369,4 @@ function tripal_entities_get_field_form_values($field_name, $form_state, $child
     }
   }
   return $values;
-}
+}