Browse Source

Merge pull request #448 from tripal/447-tv3-delete_me

Fixes the delete_me as default value.
Lacey-Anne Sanderson 6 years ago
parent
commit
50270e6c9c

+ 11 - 1
tripal/includes/TripalFields/TripalFieldWidget.inc

@@ -108,8 +108,8 @@ class TripalFieldWidget {
     );
     );
     $widget['#field'] = $this->field;
     $widget['#field'] = $this->field;
     $widget['#instance'] = $this->instance;
     $widget['#instance'] = $this->instance;
-    $widget['#element_validate'] = array('tripal_field_widget_form_validate');
     $widget['#theme'] = 'tripal_field_default';
     $widget['#theme'] = 'tripal_field_default';
+    $widget['#element_validate'] = array('tripal_field_widget_form_validate');
   }
   }
 
 
   /**
   /**
@@ -125,6 +125,16 @@ class TripalFieldWidget {
 
 
   }
   }
 
 
+  /**
+   * Performs validation of the widget form when setting defaults.
+   *
+   * Use this validate to ensure that form values are entered correctly when
+   * a user edits the defaults on the field edit page (available from the
+   * "managed fields" section of the Content type page. 
+   */
+  public function validateDefaults($element, $form, &$form_state, $langcode, $delta) {
+    
+  }
 
 
   /**
   /**
    * Performs extra commands when the entity form is submitted.
    * Performs extra commands when the entity form is submitted.

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

@@ -771,7 +771,15 @@ function tripal_field_widget_form_validate($element, &$form_state, $form) {
   tripal_load_include_field_class($widget_class);
   tripal_load_include_field_class($widget_class);
   if (class_exists($widget_class)) {
   if (class_exists($widget_class)) {
     $widget = new $widget_class($field, $instance);
     $widget = new $widget_class($field, $instance);
-    $widget->validate($element, $form, $form_state, $langcode, $delta);
+    
+    // Set the validation function for this field widget depending on the
+    // form displaying the widget.
+    if ($form['#form_id'] == 'field_ui_field_edit_form') {
+      $widget->validateDefaults($element, $form, $form_state, $langcode, $delta);
+    }
+    else {
+      $widget->validate($element, $form, $form_state, $langcode, $delta);
+    }
   }
   }
 }
 }
 
 

+ 13 - 2
tripal_chado/includes/TripalFields/chado_linker__prop/chado_linker__prop_widget.inc

@@ -7,7 +7,7 @@ class chado_linker__prop_widget extends ChadoFieldWidget {
   // The list of field types for which this formatter is appropriate.
   // The list of field types for which this formatter is appropriate.
   public static $field_types = array('chado_linker__prop');
   public static $field_types = array('chado_linker__prop');
 
 
-  /**
+    /**
    *
    *
    * @see TripalFieldWidget::form()
    * @see TripalFieldWidget::form()
    */
    */
@@ -109,6 +109,17 @@ class chado_linker__prop_widget extends ChadoFieldWidget {
       '#value' => $rank,
       '#value' => $rank,
     );
     );
   }
   }
+  
+  /**
+   * @see TripalFieldWidget::validateDefaults()
+   */
+  public function validateDefaults($element, $form, &$form_state, $langcode, $delta) {
+    $field_name = $this->field['field_name'];
+    $field_table = $this->instance['settings']['chado_table'];
+    
+    $value = $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__value'];
+    $form_state['values'][$field_name]['und'][$delta]['value'] = $value;    
+  }
 
 
   /**
   /**
    *
    *
@@ -121,7 +132,7 @@ class chado_linker__prop_widget extends ChadoFieldWidget {
     $field_table = $this->instance['settings']['chado_table'];
     $field_table = $this->instance['settings']['chado_table'];
     $chado_column = $this->instance['settings']['chado_column'];
     $chado_column = $this->instance['settings']['chado_column'];
     $instance = $this->instance;
     $instance = $this->instance;
-
+       
     $schema = chado_get_schema($field_table);
     $schema = chado_get_schema($field_table);
     $pkey = $schema['primary key'][0];
     $pkey = $schema['primary key'][0];
     $base_table = $this->instance['settings']['base_table'];
     $base_table = $this->instance['settings']['base_table'];

+ 14 - 3
tripal_chado/includes/TripalFields/data__sequence/data__sequence_widget.inc

@@ -45,8 +45,19 @@ class data__sequence_widget extends ChadoFieldWidget {
       '#cols' => 30,
       '#cols' => 30,
     );
     );
   }
   }
-
-
+  
+  /**
+   * @see TripalFieldWidget::validateDefaults()
+   */
+  public function validateDefaults($element, $form, &$form_state, $langcode, $delta) {
+    $field_name = $this->field['field_name'];
+    $field_table = $this->instance['settings']['chado_table'];
+    $field_column = $this->instance['settings']['chado_column'];
+    
+    $value = $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__' . $field_column];
+    $form_state['values'][$field_name]['und'][$delta]['value'] = $value;
+  }
+  
   /**
   /**
    *
    *
    * @see TripalFieldWidget::submit()
    * @see TripalFieldWidget::submit()
@@ -55,7 +66,7 @@ class data__sequence_widget extends ChadoFieldWidget {
     $field_name = $this->field['field_name'];
     $field_name = $this->field['field_name'];
     $field_table = $this->instance['settings']['chado_table'];
     $field_table = $this->instance['settings']['chado_table'];
     $field_column = $this->instance['settings']['chado_column'];
     $field_column = $this->instance['settings']['chado_column'];
-
+    
     // Remove any white spaces.
     // Remove any white spaces.
     $residues = $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__' . $field_column];
     $residues = $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__' . $field_column];
     if ($residues) {
     if ($residues) {

+ 2 - 2
tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference_widget.inc

@@ -99,7 +99,7 @@ class sbo__database_cross_reference_widget extends ChadoFieldWidget {
       '#disabled' => $db_id ? FALSE : TRUE,
       '#disabled' => $db_id ? FALSE : TRUE,
     );
     );
   }
   }
-
+    
   /**
   /**
    * @see TripalFieldWidget::validate()
    * @see TripalFieldWidget::validate()
    */
    */
@@ -111,7 +111,7 @@ class sbo__database_cross_reference_widget extends ChadoFieldWidget {
     $field_table = $this->instance['settings']['chado_table'];
     $field_table = $this->instance['settings']['chado_table'];
     $field_column = $this->instance['settings']['chado_column'];
     $field_column = $this->instance['settings']['chado_column'];
     $base_table = $this->instance['settings']['base_table'];
     $base_table = $this->instance['settings']['base_table'];
-
+    
     $schema = chado_get_schema($table_name);
     $schema = chado_get_schema($table_name);
     $pkey = $schema['primary key'][0];
     $pkey = $schema['primary key'][0];
     $fkeys = array_values($schema['foreign keys'][$base_table]['columns']);
     $fkeys = array_values($schema['foreign keys'][$base_table]['columns']);

+ 1 - 1
tripal_chado/includes/TripalFields/schema__alternate_name/schema__alternate_name_widget.inc

@@ -123,6 +123,7 @@ class schema__alternate_name_widget extends ChadoFieldWidget {
       '#required' => $element['#required'],
       '#required' => $element['#required'],
     );
     );
   }
   }
+    
   /**
   /**
    * @see TripalFieldWidget::validate()
    * @see TripalFieldWidget::validate()
    */
    */
@@ -139,7 +140,6 @@ class schema__alternate_name_widget extends ChadoFieldWidget {
     $fkeys = array_values($schema['foreign keys'][$base_table]['columns']);
     $fkeys = array_values($schema['foreign keys'][$base_table]['columns']);
     $fkey = $fkeys[0];
     $fkey = $fkeys[0];
 
 
-
     $pub_id = $form_state['values'][$field_name]['und'][$delta]['chado-' . $table_name . '__pub_id'];
     $pub_id = $form_state['values'][$field_name]['und'][$delta]['chado-' . $table_name . '__pub_id'];
     $syn_name = $form_state['values'][$field_name]['und'][$delta]['name'];
     $syn_name = $form_state['values'][$field_name]['und'][$delta]['name'];
     $syn_type = $form_state['values'][$field_name]['und'][$delta]['type_id'];
     $syn_type = $form_state['values'][$field_name]['und'][$delta]['type_id'];

+ 1 - 1
tripal_chado/includes/TripalFields/schema__publication/schema__publication_widget.inc

@@ -150,7 +150,7 @@ class schema__publication_widget extends ChadoFieldWidget {
     // it out so that the Chado field_storage infrastructure won't try to
     // it out so that the Chado field_storage infrastructure won't try to
     // write a record.
     // write a record.
     if (!$title) {
     if (!$title) {
-      $form_state['values'][$field_name]['und'][$delta]['value'] = '';
+      $form_state['values'][$field_name]['und'][$delta]['value'] = 'delete_me';
       $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__' . $fkey] = '';
       $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__' . $fkey] = '';
       $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__pub_id'] = '';
       $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__pub_id'] = '';
     }
     }

+ 2 - 2
tripal_chado/includes/TripalFields/sio__annotation/sio__annotation_widget.inc

@@ -174,7 +174,7 @@ class sio__annotation_widget extends ChadoFieldWidget {
       );
       );
     }
     }
   }
   }
-
+ 
   /**
   /**
    *
    *
    * @see TripalFieldWidget::submit()
    * @see TripalFieldWidget::submit()
@@ -185,7 +185,7 @@ class sio__annotation_widget extends ChadoFieldWidget {
     $field_table = $this->instance['settings']['chado_table'];
     $field_table = $this->instance['settings']['chado_table'];
     $field_column = $this->instance['settings']['chado_column'];
     $field_column = $this->instance['settings']['chado_column'];
     $base_table = $this->instance['settings']['base_table'];
     $base_table = $this->instance['settings']['base_table'];
-
+    
     // Get the FK that links to the base record.
     // Get the FK that links to the base record.
     $schema = chado_get_schema($field_table);
     $schema = chado_get_schema($field_table);
     $pkey = $schema['primary key'][0];
     $pkey = $schema['primary key'][0];