Ver código fonte

Fixed chado_liner_relationship instanceSettingFormValidate()

Chun-Huai Cheng 8 anos atrás
pai
commit
47fdc0ce2a

+ 4 - 4
tripal/includes/TripalField.inc

@@ -517,8 +517,8 @@ class TripalField {
     //       '#collapsible' => TRUE,
     //       '#tree' => TRUE,
     //     );
-    //$element['#field'] = $this->field;
-    //$element['#instance'] = $this->instance;
+    $element['#field'] = $this->field;
+    $element['#instance'] = $this->instance;
     $element['#element_validate'][] = 'tripal_field_instance_settings_form_validate';
 
     return $element;
@@ -568,8 +568,8 @@ class TripalField {
 //       '#collapsible' => TRUE,
 //       '#tree' => TRUE,
 //     );
-//    $element['#field'] = $this->field;
-//    $element['#instance'] = $this->instance;
+    $element['#field'] = $this->field;
+    $element['#instance'] = $this->instance;
     $element['#element_validate'][] = 'tripal_field_settings_form_validate';
 
     return $element;

+ 1 - 1
tripal/includes/tripal.fields.inc

@@ -249,7 +249,7 @@ function tripal_field_instance_settings_form_validate($form, &$form_state) {
   $is_loaded = tripal_load_include_field_type($field_type);
   if ($is_loaded) {
     $tfield = new $field_type($field, $instance);
-    $form = $tfield->instanceSettingsFormValidate($field, $instance, $form, $form_state);
+    $form = $tfield->instanceSettingsFormValidate($form, $form_state);
   }
 }
 

+ 36 - 32
tripal_chado/includes/TripalFields/chado_linker__relationship.inc

@@ -293,7 +293,7 @@ class chado_linker__relationship extends TripalField {
       $subject_id = $item[$field_table . '__subject_id'];
       $object_id = $item[ $field_table . '__object_id'];
       $type_id = $item[$field_table . '__type_id'];
-      $type_name = $item['type_name'];
+      $type_name = isset($item['type_name']) ? $item['type_name'] : '';
       $subject_name = $item['subject_name'];
       $object_name = $item['object_name'];
 
@@ -841,37 +841,41 @@ class chado_linker__relationship extends TripalField {
    */
   public function instanceSettingsFormValidate($form, &$form_state) {
     //dpm($form);dpm($form_state);
-//     $settings = $form_state['values']['instance']['settings'];
-
-//     // Make sure the supplied types are valid cvterms
-//     if (isset($settings['relationship_types'])) {
-//       $rel_types = explode(PHP_EOL, $settings['relationship_types']);
-//       foreach($rel_types AS $type) {
-//         // Ignore empty lines
-//         if (trim($type) == '') {
-//           continue;
-//         }
-//         $term = tripal_get_cvterm(array('name' => trim($type)));
-//         // Don't save the form  if a term can not be found or it matches more than one cvterm
-//         if (!isset($term->cvterm_id)) {
-//           form_set_error(
-//             "instance][settings][relationships][relationship_types",
-//             t("The term '@type' can not be found or matches more than one term.", array('@type' => $type))
-//           );
-//         }
-//       }
-//     }
-//     // Make sure child relationship types are using a valid cvterm
-//     if (isset($settings['child_relationship_types'])) {
-//       $supertype = $settings['child_relationship_types'];
-//       $term = tripal_get_cvterm(array('name' => trim($supertype)));
-//       if (!isset($term->cvterm_id)) {
-//         form_set_error(
-//           "instance][settings][relationships][child_relationship_types",
-//           t("The term '@type' can not be found or matches more than one term.", array('@type' => $supertype))
-//         );
-//       }
-//     }
+     $settings = $form_state['values']['instance']['settings']['relationships'];
+
+     // Make sure the supplied types are valid cvterms
+     if (isset($settings['relationship_types'])) {
+       $rel_types = explode(PHP_EOL, $settings['relationship_types']);
+       foreach($rel_types AS $type) {
+         // Ignore empty lines
+         if (trim($type) == '') {
+           continue;
+         }
+         $term = tripal_get_cvterm(array('name' => trim($type)));
+         // Don't save the form  if a term can not be found or it matches more than one cvterm
+         if (!isset($term->cvterm_id)) {
+           form_set_error(
+             "instance][settings][relationships][relationship_types",
+             t("The term '@type' can not be found or matches more than one term.", array('@type' => $type))
+           );
+         }
+       }
+     }
+     // Make sure child relationship types are using a valid cvterm
+     if (isset($settings['option2_parent']) && $settings['option2_parent']) {
+       $cv_id = $settings['option2_vocab'];
+       $supertype = $settings['option2_parent'];
+       $term = tripal_get_cvterm(array(
+         'name' => trim($supertype),
+         'cv_id' => $cv_id
+       ));
+       if (!isset($term->cvterm_id)) {
+         form_set_error(
+           "instance][settings][relationships][option2_parent",
+           t("The term '@type' is not a valid term for the vocabulary selected.", array('@type' => $supertype))
+         );
+       }
+     }
   }
 }