Browse Source

fixes requested for PR

Stephen Ficklin 6 years ago
parent
commit
f4d1c3d941

+ 8 - 0
tripal_chado/includes/TripalFields/data__accession/data__accession_widget.inc

@@ -94,6 +94,14 @@ class data__accession_widget extends ChadoFieldWidget {
     $dbxref_id = $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__dbxref_id'];
     $db_id = $form_state['values'][$field_name]['und'][$delta]['db_id'];
     $accession = $form_state['values'][$field_name]['und'][$delta]['accession'];
+    
+    // Is this field required?
+    if ($element['#required'] and !$db_id) {
+      form_set_error($field_name . '][und][0][db_id', "A database for the accession must be provided.");
+    }
+    if ($element['#required'] and !$accession) {
+      form_set_error($field_name . '][und][0][accession', "An accession number must be provided.");
+    }
 
     // If user did not select a database, we want to remove dbxref_id from the
     // field. We use '__NULL__' because this field is part of the base table

+ 0 - 35
tripal_chado/includes/TripalFields/operation__analysis/operation__analysis.inc

@@ -35,45 +35,10 @@ class operation__analysis extends ChadoField {
   public static $default_formatter = 'operation__analysis_formatter';
 
 
-  /**
-   * @see TripalField::validate()
-   */
-  public function validate($entity_type, $entity, $langcode, $items, &$errors) {
-
-    // If we don't have an entity then we don't want to validate.  The case
-    // where this could happen is when a user is editing the field settings
-    // and trying to set a default value. In that case there's no entity and
-    // we don't want to validate.  There will always be an entity for creation
-    // and update operations of a content type.
-    if (!$entity) {
-      return;
-    }
-    $settings = $this->field['settings'];
-    $field_name = $this->field['field_name'];
-    $field_type = $this->field['type'];
-    $field_table = $this->instance['settings']['chado_table'];
-    $field_column = $this->instance['settings']['chado_column'];
-    $linker_field = 'chado-' . $field_table . '__' . $field_column;
-    
-    // Get the field values.
-    foreach ($items as $delta => $values) {
-
-      // Get the field values.
-      $analysis_id = $values[$linker_field];
-      if (!$analysis_id or $analysis_id == 0) {
-        $errors[$field_name]['und'][0][] = [
-          'message' =>  t("Please specify an analysis."),
-          'error' => 'operation__analysis'
-        ];
-      }
-    }
-  }
-
   /**
    * @see TripalField::load()
    */
   public function load($entity) {
-
     $record = $entity->chado_record;
     $settings = $this->instance['settings'];
 

+ 3 - 2
tripal_chado/includes/tripal_chado.fields.inc

@@ -847,7 +847,7 @@ function tripal_chado_bundle_instances_info($entity_type, $bundle) {
   tripal_chado_bundle_instances_info_base($info, $entity_type, $bundle, $details);
   tripal_chado_bundle_instances_info_custom($info, $entity_type, $bundle, $details);
   tripal_chado_bundle_instances_info_linker($info, $entity_type, $bundle, $details);
-
+dpm($info);
   return $info;
 
 }
@@ -1543,7 +1543,8 @@ function tripal_chado_bundle_instances_info_custom(&$info, $entity_type, $bundle
   if (array_key_exists('dbxref_id', $schema['fields'])) {
     $field_name = 'data__accession';
     $required = FALSE;
-    if ($table == 'phylotree') {
+    if (array_key_exists('not null', $schema['fields']['dbxref_id']) and
+        $schema['fields']['dbxref_id']['not null']) {
       $required = TRUE;
     }
     $info[$field_name] = array(

+ 6 - 1
tripal_chado/includes/tripal_chado.phylotree.inc

@@ -5,6 +5,11 @@
  * @param $phylotree
  */
 function tripal_phylogeny_prepare_tree_viewer($phylotree) {
+  
+  // If the phylotree is not provided then just return;
+  if (!$phylotree) {
+    tripal_report_error('tripal_phylotree', TRIPAL_ERROR, 'tripal_phylogeny_prepare_tree_viewer: must provide a $phylotree argument.');
+  }
 
   // Don't prepare for viewing more than once.
   if (property_exists($phylotree, 'prepared_to_view') and
@@ -24,7 +29,7 @@ function tripal_phylogeny_prepare_tree_viewer($phylotree) {
 
   // Don't show tick marks for the taxonomy tree.
   $skip_ticks = 0;
-  if ($phylotree->type_id->name == 'taxonomy' or $phylotree->type_id->name == 'Species tree') {
+  if (!is_null($phylotree->type_id) and ($phylotree->type_id->name == 'taxonomy' or $phylotree->type_id->name == 'Species tree')) {
     $skip_ticks = 1;
   }