Browse Source

Working on propadder field

Chun-Huai Cheng 8 years ago
parent
commit
74f8d416fc

+ 1 - 1
tripal_chado/includes/TripalFields/chado_linker__prop.inc

@@ -181,7 +181,7 @@ class chado_linker__prop extends TripalField {
       if (!trim($item['chado-' . $field_table . '__' . 'value'])) {
         foreach($item AS $key => $value) {
           if (preg_match('/^chado-/', $key)) {
-            $items[$delta][$key] = '__NULL__';
+            //$items[$delta][$key] = '__NULL__';
           }
         }
       }

+ 19 - 4
tripal_chado/includes/TripalFields/chado_linker__prop_adder.inc

@@ -90,6 +90,23 @@ class chado_linker__prop_adder extends TripalField {
     $kvproperty = tripal_get_field_item_keyval($items, $delta, 'value', '');
     $cvterms = chado_generate_var('cvterm', array('name' => $kvproperty), $options = array('return_array' => TRUE));
 
+    if (trim($kvproperty) && count($cvterms) == 1) {
+      // Get the table and base table.
+      $base_table = $this->field['settings']['base_table'];
+      
+      // Generate the name for the property table and the field name that we'll
+      // be creating.
+      $prop_table = $base_table . 'prop';
+      $field_name = $prop_table . '__' . $cvterms[0]->cvterm_id;
+      // Create an instance of the field.
+      $instance = field_info_instance($entity_type, $field_name,  $entity->bundle);
+      if ($instance) {
+        $errors[$this->field['field_name']][$langcode][$delta][] = array(
+          'error' => 'chado_linker__prop_adder',
+          'message' => t("The property already exists."),
+        );
+      }
+    }
     if (trim($kvproperty) && count($cvterms) > 1) {
       $errors[$this->field['field_name']][$langcode][$delta][] = array(
         'error' => 'chado_linker__prop_adder',
@@ -161,10 +178,8 @@ class chado_linker__prop_adder extends TripalField {
     }
 
     // Create an instance of the field.
-    if (!$field and array_key_exists('bundles', $field) or
-        !array_key_exists('TripalEntity', $field['bundles']) or
-        !in_array($bundle_name, $field['bundles']['TripalEntity'])) {
-
+    $instance = field_info_instance($entity_type, $field_name,  $entity->bundle);
+    if (!$instance) {
       $instance = field_create_instance(array(
         'field_name' => $field_name,
         'entity_type' => 'TripalEntity',