Преглед изворни кода

Fixed code after moving chado field creation into hook_chado_field_alter

Chun-Huai Cheng пре 9 година
родитељ
комит
4dfc393d1a

+ 6 - 1
tripal_entities/includes/tripal_entities.admin.inc

@@ -433,7 +433,7 @@ function tripal_entities_add_bundle_fields($entity_type_name, $bundle_name, $cvt
         'widget_type' => '',
         'settings' => array(),
         'description' => '',
-        'label' => $label ? $label : ucwords(preg_replace('/_/', ' ', $column_name)),
+        'label' => ucwords(preg_replace('/_/', ' ', $column_name)),
         'chado_table' => $tablename,
         'chado_column' => $column_name
       );
@@ -442,10 +442,12 @@ function tripal_entities_add_bundle_fields($entity_type_name, $bundle_name, $cvt
       switch($details['type']) {
         case 'char':
           $field_info['field_type'] = 'text';
+          $field_info['widget_type'] = 'text_textfield';
           $field_info['settings']['max_length'] = $details['length'];
           break;
         case 'varchar':
           $field_info['field_type'] = 'text';
+          $field_info['widget_type'] = 'text_textfield';
           $field_info['settings']['max_length'] = $details['length'];
           break;
         case 'text':
@@ -483,6 +485,9 @@ function tripal_entities_add_bundle_fields($entity_type_name, $bundle_name, $cvt
           // Use the Drupal Date and Date API to create the field/widget
           $field_info['field_type'] = 'datetime';
           $field_info['widget_type'] = 'date_select';
+          $field_info['settings']['increment '] = 1;
+          $field_info['settings']['tz_handling'] = 'none';
+          
           // TODO: Add settings so that the minutes increment by 1.
           // And turn off the timezone, as the Chado field doesn't support it.
           break;

+ 4 - 5
tripal_entities/includes/tripal_entities.chado_entity.inc

@@ -82,7 +82,7 @@ function tripal_entities_field_widget_form_alter(&$element, &$form_state, $conte
       $colname = $matches[2];
       $schema = chado_get_schema($tablename);
       if ($colname == 'timelastmodified' and
-          $schema['fields'][$colname]['type'] == 'datetime') {
+        $schema['fields'][$colname]['type'] == 'datetime') {
         $element['#default_value']['value'] = format_date(time(), 'custom', "Y-m-d H:i:s");
         $element['#date_items']['value'] = $element['#default_value']['value'];
         $form_state['rebuild'] = TRUE;
@@ -94,7 +94,7 @@ function tripal_entities_field_widget_form_alter(&$element, &$form_state, $conte
  * Implements hook_chado_field_alter().
  *
  */
-function tripal_entities_chado_field_alter($field) {
+function tripal_entities_chado_field_alter(&$field) {
 
   // Here we provide new field types and widgets for FK fields
   // and fields that need special attention.
@@ -111,14 +111,13 @@ function tripal_entities_chado_field_alter($field) {
     $field['description'] = 'This record can be cross-referenced with a record in another online database. This field is intended for the most prominent reference.  At a minimum, the database and accession must be provided.';
   }
   else if ($field['chado_table'] == 'feature' and
-           $field['chado_column'] == 'md5checksum') {
+    $field['chado_column'] == 'md5checksum') {
     $field['field_type'] = 'md5checksum';
     $field['widget_type'] = 'tripal_entities_md5checksum_checkbox_widget';
     $field['label'] = 'MD5 Checksum';
     $field['description'] = 'Generating MD5 checksum for the sequence.';
   }
   else if ($field['chado_table'] == 'feature' and
-           $field['chado_column'] == 'seqlen') {
-
+    $field['chado_column'] == 'seqlen') {
   }
 }

+ 12 - 4
tripal_entities/includes/tripal_entities.fields.inc

@@ -323,11 +323,19 @@ function tripal_entities_primary_dbxref_widget_validate($element, &$form_state)
  * Callback function for validating the tripal_entities_md5checksum_checkbox_widget.
  */
 function tripal_entities_md5checksum_checkbox_widget_validate($element, &$form_state) {
-  // Calculate the md5 checksum for the sequence per user's request
-  if (key_exists('feature__md5checksum', $field_vals) && key_exists('feature__residues', $field_vals)) {
-    $residues = $field_vals['feature__residues'];
-    $field_vals['feature__md5checksum'] = $field_vals['feature__md5checksum'] ? md5($residues) : NULL;
+  
+  $field_name = $element['#field_name'];
+
+  // Calculate the md5 checksum for the sequence only if md5 box is checked and the residues exist
+  $residues = tripal_entities_get_field_form_values('feature__residues', $form_state);
+  if (count($residues) > 0 && trim($residues[0]) != '') {    
+    tripal_entities_set_field_form_values ($field_name, $form_state, md5($residues[0]));
   }
+  else {
+    // Otherwise, remove the md5 value
+    tripal_entities_set_field_form_values ($field_name, $form_state, '__NULL__');
+  }
+
 }
 /**
  * Theme function for the primary_dbxref_widget.

+ 1 - 0
tripal_entities/tripal_entities.module

@@ -378,6 +378,7 @@ function tripal_entity_load($id, $reset = FALSE) {
  * @param unknown $form_state
  */
 function tripal_entities_form_alter(&$form, &$form_state, $form_id) {
+
   switch ($form_id) {
     case 'field_ui_field_edit_form':
       // For entity fields added by Tripal Entities we don't want the