Procházet zdrojové kódy

Fixed various fields and other bugs

Stephen Ficklin před 7 roky
rodič
revize
d8f42cb817

+ 5 - 0
tripal/includes/TripalFields/TripalField.inc

@@ -375,6 +375,11 @@ class TripalField {
     if ($element_name == 'entity') {
       return;
     }
+
+    if (!preg_match('/:/', $element_name)) {
+      return;
+    }
+
     $field_name = $parent . '.' . $element_name;
     list($vocabulary, $accession) = explode(':', $element_name);
     $term = tripal_get_term_details($vocabulary, $accession);

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

@@ -94,6 +94,7 @@ class chado_linker__prop_widget extends ChadoFieldWidget {
       '#default_value' => $value,
       '#title' => $instance['label'],
       '#description' => $instance['description'],
+      '#rows' => 1,
     );
     $widget['chado-' . $field_table . '__type_id'] = array(
       '#type' => 'hidden',

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

@@ -76,12 +76,6 @@ class data__accession_widget extends ChadoFieldWidget {
       '#maxlength' => array_key_exists('length', $schema['fields']['accession']) ? $schema['fields']['accession']['length'] : 255,
       '#size' => 15,
       '#autocomplete_path' => 'admin/tripal/storage/chado/auto_name/dbxref/' . $db_id,
-      '#ajax' => array(
-        'callback' => "data__accession_widget_form_ajax_callback",
-        'wrapper' => "$field_name-dbxref--db-id",
-        'effect' => 'fade',
-        'method' => 'replace'
-      ),
       '#disabled' => $db_id ? FALSE : TRUE,
     );
   }

+ 2 - 2
tripal_chado/includes/TripalFields/sbo__phenotype/sbo__phenotype.inc

@@ -65,8 +65,8 @@ class sbo__phenotype extends ChadoField {
     return array(
       $field_term => array(
         'operations' => array('eq', 'ne', 'contains', 'starts'),
-        'sortable' => TRUE,
-        'searchable' => TRUE,
+        'sortable' => FALSE,
+        'searchable' => FALSE,
       ),
     );
   }

+ 39 - 1
tripal_chado/includes/TripalFields/schema__additional_type/schema__additional_type.inc

@@ -35,6 +35,14 @@ class schema__additional_type extends ChadoField {
     // type. This will create form elements when editing the field instance
     // to allow the site admin to change the term settings above.
     'term_fixed' => FALSE,
+    // The name of the vocabulary that should be used to provide a list
+    // of terms to select form when providing the additional type.
+    // This should be the name of the controlled vocabulary from the cv table.
+    'vocabulary' => '',
+    // If the entire vocabulary is not to be used for the types and if the
+    // vocabulary is heirarchical then this will be the parent term.
+    // This should be of the format {db.name}:{dbxref.accession}
+    'parent_term' => '',
   );
 
   // The default widget for this field.
@@ -43,6 +51,37 @@ class schema__additional_type extends ChadoField {
   // The default formatter for this field.
   public static $default_formatter = 'schema__additional_type_formatter';
 
+  /**
+   * @see ChadoField::query()
+   */
+  public function query($query, $condition) {
+    $alias = $this->field['field_name'];
+    $operator = $condition['operator'];
+
+    $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'];
+
+    $this->queryJoinOnce($query, 'cvterm', $alias, "base.$field_column = $alias.cvterm_id");
+    $query->condition($alias . '.name' , $condition['value'], $operator);
+  }
+
+  /**
+   * @see ChadoField::query()
+   */
+  public function queryOrder($query, $order) {
+    dpm('hi');
+    $alias = $this->field['field_name'];
+
+    $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'];
+
+    $this->queryJoinOnce($query, 'cvterm', $alias, "base.$field_column = $alias.cvterm_id", "LEFT OUTER");
+    $query->orderBy($alias . '.name' , $order['direction']);
+  }
 
   /**
    *
@@ -57,7 +96,6 @@ class schema__additional_type extends ChadoField {
     $field_table = $this->instance['settings']['chado_table'];
     $field_column = $this->instance['settings']['chado_column'];
 
-
     // Set some defaults for the empty record.
     $entity->{$field_name}['und'][0] = array(
       'value' => $record->type_id->name,

+ 8 - 5
tripal_chado/includes/TripalFields/schema__additional_type/schema__additional_type_formatter.inc

@@ -12,11 +12,14 @@ class schema__additional_type_formatter extends ChadoFieldFormatter {
    * @see TripalFieldFormatter::view()
    */
   public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
-    foreach ($items as $delta => $item) {
-      $element[$delta] = array(
-        '#type' => 'markup',
-        '#markup' => $item['value'],
-      );
+    $content = '';
+    if (count($items) > 0) {
+      $content = $items[0]['value'];
     }
+
+    $element[0] = array(
+      '#type' => 'markup',
+      '#markup' => $content,
+    );
   }
 }

+ 80 - 1
tripal_chado/includes/TripalFields/schema__additional_type/schema__additional_type_widget.inc

@@ -14,13 +14,92 @@ class schema__additional_type_widget extends ChadoFieldWidget {
   public function form(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
     parent::form($widget, $form, $form_state, $langcode, $items, $delta, $element);
 
+    $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'];
+    $vocabulary = $this->instance['settings']['vocabulary'];
+    $parent_term = $this->instance['settings']['parent_term'];
+
+    $record_id = $element['#entity']->chado_record_id;
+    $value = '';
+    $type_id = '';
+
+    if (count($items) > 0) {
+      $type_id = $items[0]['chado-' . $field_table . '__type_id'];
+      $value = $items[0]['value'];
+    }
+
+    if (array_key_exists('values', $form_state) and array_key_exists($field_name, $form_state['values'])) {
+      $type_id = $form_state['values'][$field_name][$langcode][$delta]['value'];
+    }
+
+    $widget['value'] = array(
+      '#type' => 'value',
+      '#value' => $value,
+    );
+
+    // If a parent_term is provided then use that to get the options
+    $options = array();
+    $options[] = 'Select a type';
+    if ($parent_term) {
+      list ($vocabulary, $accession) = explode(':', $parent_term);
+      if ($vocabulary and $accession) {
+        $sql = "
+          SELECT
+            CVTS.cvterm_id, CVTS.name
+          FROM {cvtermpath} CVTP
+            INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
+            INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
+            INNER JOIN {dbxref} DBXO ON DBXO.dbxref_id = CVTO.dbxref_id
+            INNER JOIN {db} DBO      ON DBO.db_id = DBXO.db_id
+          WHERE
+            DBO.name = :vocabulary AND DBXO.accession = :accession AND
+            NOT CVTS.is_obsolete = 1
+          ORDER BY CVTS.name ASC
+       ";
+        $results = chado_query($sql, array(':vocabulary' => $vocabulary, ':accession' => $accession));
+        while ($term = $results->fetchObject()) {
+          $options[$term->cvterm_id] = $term->name;
+        }
+      }
+    }
+    elseif ($vocabulary) {
+      $cv = tripal_get_cv(array('name' => $vocabulary));
+      $options = tripal_get_cvterm_select_options($cv->cv_id);
+    }
+    $widget['chado-' . $field_table . '__type_id'] = array(
+      '#type' => 'select',
+      '#options' => $options,
+      '#title' => $element['#title'],
+      '#description' => $element['#description'],
+      '#weight' => isset($element['#weight']) ? $element['#weight'] : 0,
+      '#default_value' => $type_id,
+      '#delta' => $delta,
+    );
   }
 
   /**
    *
    * @see TripalFieldWidget::submit()
    */
-  public function submit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
+  public function validate($element, $form, &$form_state, $langcode, $delta) {
+    $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'];
+    $vocabulary = $this->instance['settings']['vocabulary'];
+    $parent_term = $this->instance['settings']['parent_term'];
+
+    $type_id = $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__type_id'];
 
+    if (!$type_id) {
+      $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__type_id'] = '__NULL__';
+    }
+    else {
+      $form_state['values'][$field_name]['und'][$delta]['value'] = $type_id;
+    }
   }
 }

+ 50 - 33
tripal_chado/includes/TripalFields/schema__alternate_name/schema__alternate_name_widget.inc

@@ -72,10 +72,9 @@ class schema__alternate_name_widget extends ChadoFieldWidget {
     // size of the name field to the proper size.
     $schema = chado_get_schema('synonym');
 
-    $widget['#table_name'] = $table_name;
-    $widget['#fkey_field'] = $fkey;
     $widget['#prefix'] =  "<span id='$table_name-$delta'>";
     $widget['#suffix'] =  "</span>";
+    $widget['#table_name'] = $table_name;
 
     $widget['value'] = array(
       '#type' => 'value',
@@ -126,12 +125,7 @@ class schema__alternate_name_widget extends ChadoFieldWidget {
       '#required' => $element['#required'],
     );
   }
-
-  /**
-   *
-   * @see TripalFieldWidget::submit()
-   */
-  public function submit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
+  public function validate($element, $form, &$form_state, $langcode, $delta) {
     $field_name = $this->field['field_name'];
     $field_type = $this->field['type'];
     $table_name = $this->instance['settings']['chado_table'];
@@ -143,14 +137,53 @@ class schema__alternate_name_widget extends ChadoFieldWidget {
     $fkeys = array_values($schema['foreign keys'][$base_table]['columns']);
     $fkey = $fkeys[0];
 
-    $record_id = isset($form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__' . $pkey]) ? $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__' . $pkey] : '';
-    $fkey_value = isset($form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__' . $fkey]) ? $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__' . $fkey] : '';
-    $synonym_id = isset($form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__synonym_id']) ? $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__synonym_id'] : '';
-    $pub_id = isset($form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__pub_id']) ? $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__pub_id'] : '';
-    $is_current = isset($form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__is_current']) ? $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__is_current'] : '';
-    $is_internal = isset($form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__is_internal']) ? $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__is_internal'] : '';
-    $syn_name = isset($form_state['values'][$field_name][$langcode][$delta]['name']) ? $form_state['values'][$field_name][$langcode][$delta]['name'] : '';
-    $syn_type = isset($form_state['values'][$field_name][$langcode][$delta]['type_id']) ? $form_state['values'][$field_name][$langcode][$delta]['type_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_type = $form_state['values'][$field_name]['und'][$delta]['type_id'];
+
+    // If the user provided a $syn_name and a $syn_type then we want to set
+    // the foreign key value to be the chado_record_id.
+    if ($syn_name and $syn_type) {
+      // Set the synonym_id and FK value
+      $synonym = chado_generate_var('synonym', array('name' => $syn_name, 'type_id' => $syn_type));
+      if ($synonym) {
+        $form_state['values'][$field_name]['und']['value'] = $synonym->synonym_id;
+        $form_state['values'][$field_name]['und'][$delta]['chado-' . $table_name . '__synonym_id'] = $synonym->synonym_id;
+      }
+      else {
+        $form_state['values'][$field_name]['und']['value'] = $syn_name;
+      }
+      // If a publication is not provided then use the null pub.
+      if (!$pub_id) {
+        $pub = chado_generate_var('pub', array('uniquename' => 'null'));
+        $form_state['values'][$field_name]['und'][$delta]['chado-' . $table_name . '__pub_id'] = $pub->pub_id;
+      }
+    }
+    // If no snynonym name is provided then we want to delete the record.
+    // To do this we have to set the value to something (here we just use
+    // the arbitrary 'delete_me', and set every other element to empty other
+    // than the pkey element.
+    else {
+      $form_state['values'][$field_name]['und'][$delta]['value'] = 'delete_me';
+      $form_state['values'][$field_name]['und'][$delta]['chado-' . $table_name . '__' . $fkey] = '';
+      $form_state['values'][$field_name]['und'][$delta]['chado-' . $table_name . '__synonym_id'] = '';
+      $form_state['values'][$field_name]['und'][$delta]['chado-' . $table_name . '__is_internal'] = '';
+      $form_state['values'][$field_name]['und'][$delta]['chado-' . $table_name . '__is_current'] = '';
+      $form_state['values'][$field_name]['und'][$delta]['chado-' . $table_name . '__pub_id'] = '';
+    }
+  }
+
+  /**
+   *
+   * @see TripalFieldWidget::submit()
+   */
+  public function submit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
+    $field_name = $this->field['field_name'];
+    $table_name = $this->instance['settings']['chado_table'];
+
+    $syn_name = $form_state['values'][$field_name]['und'][$delta]['name'];
+    $syn_type = $form_state['values'][$field_name]['und'][$delta]['type_id'];
 
     // If the user provided a $syn_name and a $syn_type then we want to set
     // the foreign key value to be the chado_record_id.
@@ -166,23 +199,8 @@ class schema__alternate_name_widget extends ChadoFieldWidget {
           'synonym_sgml' => '',
         ));
         $synonym = (object) $synonym;
+        $form_state['values'][$field_name]['und'][$delta]['chado-' . $table_name . '__synonym_id'] = $synonym->synonym_id;
       }
-
-      // Set the synonym_id and FK value
-      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__synonym_id'] = $synonym->synonym_id;
-
-      if (!$pub_id) {
-        $pub = chado_generate_var('pub', array('uniquename' => 'null'));
-        $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__pub_id'] = $pub->pub_id;
-      }
-    }
-    else {
-      // If the $syn_name is not set, then remove the linker FK value to the base table.
-      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__' . $fkey] = '';
-      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__synonym_id'] = '';
-      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__is_internal'] = '';
-      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__is_current'] = '';
-      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__pub_id'] = '';
     }
   }
 
@@ -194,7 +212,6 @@ class schema__alternate_name_widget extends ChadoFieldWidget {
     // These two fields were added to the widget to help identify the fields
     // for layout.
     $table_name = $element['#table_name'];
-    $fkey = $element['#fkey_field'];
 
     $layout = "
       <div class=\"synonym-widget\">

+ 0 - 7
tripal_chado/includes/TripalFields/so__genotype/so__genotype.inc

@@ -63,32 +63,25 @@ class so__genotype extends ChadoField {
     $field_term = $this->getFieldTermID();
     return array(
       $field_term => array(
-        'operations' => array(),
         'sortable' => FALSE,
         'searchable' => FALSE,
         'elements' => array(
           'rdfs:type' => array(
             'searchable' => FALSE,
-            'name' => 'genotype_type_name',
             'label' => 'Genotype Type',
             'help' => 'The type of genotype.',
-            'operations' => array('eq', 'ne', 'contains', 'starts'),
             'sortable' => FALSE,
           ),
           'schema:name' => array(
-            'name' => 'genotype_name',
             'label' => 'Genotype Name',
             'help' => 'The name of the genotype.',
             'searchable' => FALSE,
-            'operations' => array('eq', 'ne', 'contains', 'starts'),
             'sortable' => FALSE,
           ),
           'schema:description' => array(
-            'name' => 'genotype_description',
             'label' => 'Genotype Description',
             'help' => 'A description of the genotype.',
             'searchable' => FALSE,
-            'operations' => array('eq', 'ne', 'contains', 'starts'),
             'sortable' => FALSE,
           ),
         )

+ 2 - 2
tripal_chado/includes/tripal_chado.field_storage.inc

@@ -628,8 +628,8 @@ function tripal_chado_field_storage_query($query) {
     } // end if ($sort['type'] == 'field') {
   } // end foreach ($query->order as $index => $sort) {
 
-      dpm($cquery->__toString());
-      dpm($cquery->getArguments());
+       dpm($cquery->__toString());
+       dpm($cquery->getArguments());
 
   $records = $cquery->execute();
 

+ 220 - 181
tripal_chado/includes/tripal_chado.fields.inc

@@ -95,7 +95,7 @@ function tripal_chado_bundle_fields_info_base(&$info, $details, $entity_type, $b
         array('%table_name' => $table_name, '%column_name' => $column_name)), 'error');
       continue;
     }
-    $field_name = strtolower($cvterm->dbxref_id->db_id->name . '__' . preg_replace('/ /', '_', $cvterm->name));
+    $field_name = strtolower($cvterm->dbxref_id->db_id->name . '__' . preg_replace('/[^\w]/', '_', $cvterm->name));
     $field_name = substr($field_name, 0, 32);
 
     // Skip the primary key field.
@@ -103,9 +103,9 @@ function tripal_chado_bundle_fields_info_base(&$info, $details, $entity_type, $b
       continue;
     }
 
-    // Skip the type field that will always be custom
-    if (($table_name == $type_table and $column_name == $type_column) or
-         $column_name == 'type_id') {
+    // If the type_id defines the content type and it's part of the
+    // base table and this column is the type_id then skip it.
+    if (!$type_table and $type_column and $column_name == $type_column) {
       continue;
     }
 
@@ -172,7 +172,9 @@ function tripal_chado_bundle_fields_info_base(&$info, $details, $entity_type, $b
     //
     // PUB TABLE
     //
-    elseif ($table_name == 'pub' and $column_name == 'uniquename') {
+    if ($table_name == 'pub' and (
+        $column_name == 'uniquename' or $column_name == 'title' or
+        $column_name == 'volumetitle')) {
       $base_info['type'] = 'text';
       $base_info['settings']['text_processing'] = 0;
     }
@@ -194,12 +196,8 @@ function tripal_chado_bundle_fields_info_custom(&$info, $details, $entity_type,
 
   $schema = chado_get_schema($table_name);
 
-  // BASE TYPE_ID
-  // Exclude the type_id field on base tables where content types are mapped
-  // by the type_id field or on the organism table where the type_id is mean
-  // as an infraspecific name type.
-  if (array_key_exists('type_id', $schema['fields']) and
-      $table_name != 'organism' and $type_column != 'type_id') {
+  // An additional type for the publication
+  if ($table_name == 'pub') {
     $field_name = 'schema__additional_type';
     $field_type = 'schema__additional_type';
     $info[$field_name] = array(
@@ -304,7 +302,7 @@ function tripal_chado_bundle_fields_info_custom(&$info, $details, $entity_type,
     );
   }
 
-  // PROTEIN & CDS SEQUENCE
+  // PROTEIN & CDS
   if ($table_name == 'feature' and
       ($bundle->label == 'mRNA' or $bundle->label == 'transcript'))  {
     $field_name = 'data__protein_sequence';
@@ -332,21 +330,21 @@ function tripal_chado_bundle_fields_info_custom(&$info, $details, $entity_type,
 //     );
   }
 
-  // GENE TRANSCRIPTS
-  $rel_table = $table_name . '_relationship';
-  if (chado_table_exists($rel_table) and $bundle->label == 'gene') {
-    $field_name = 'so__transcript';
-    $field_type = 'so__transcript';
-    $info[$field_name] = array(
-      'field_name' => $field_name,
-      'type' => $field_type,
-      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
-      'locked' => FALSE,
-      'storage' => array(
-        'type' => 'field_chado_storage',
-      ),
-    );
-  }
+//   // GENE TRANSCRIPTS
+//   $rel_table = $table_name . '_relationship';
+//   if (chado_table_exists($rel_table) and $bundle->label == 'gene') {
+//     $field_name = 'so__transcript';
+//     $field_type = 'so__transcript';
+//     $info[$field_name] = array(
+//       'field_name' => $field_name,
+//       'type' => $field_type,
+//       'cardinality' => FIELD_CARDINALITY_UNLIMITED,
+//       'locked' => FALSE,
+//       'storage' => array(
+//         'type' => 'field_chado_storage',
+//       ),
+//     );
+//   }
 
   // ORGANISM TYPE_ID
   if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
@@ -502,37 +500,37 @@ function tripal_chado_bundle_fields_info_linker(&$info, $details, $entity_type,
     );
   }
 
-  // GENOTYPE
-  $genotype_table = $table_name . '_genotype';
-  if (chado_table_exists($genotype_table)) {
-    $field_name = 'so__genotype';
-    $field_type = 'so__genotype';
-    $info[$field_name] = array(
-      'field_name' => $field_name,
-      'type' => $field_type,
-      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
-      'locked' => FALSE,
-      'storage' => array(
-        'type' => 'field_chado_storage',
-      ),
-    );
-  }
+//   // GENOTYPE
+//   $genotype_table = $table_name . '_genotype';
+//   if (chado_table_exists($genotype_table)) {
+//     $field_name = 'so__genotype';
+//     $field_type = 'so__genotype';
+//     $info[$field_name] = array(
+//       'field_name' => $field_name,
+//       'type' => $field_type,
+//       'cardinality' => FIELD_CARDINALITY_UNLIMITED,
+//       'locked' => FALSE,
+//       'storage' => array(
+//         'type' => 'field_chado_storage',
+//       ),
+//     );
+//   }
 
-  // PHENOTYPE
-  $phenotype_table = $table_name . '_phenotype';
-  if (chado_table_exists($phenotype_table)) {
-    $field_name = 'sbo__phenotype';
-    $field_type = 'sbo__phenotype';
-    $info[$field_name] = array(
-      'field_name' => $field_name,
-      'type' => $field_type,
-      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
-      'locked' => FALSE,
-      'storage' => array(
-        'type' => 'field_chado_storage',
-      ),
-    );
-  }
+//   // PHENOTYPE
+//   $phenotype_table = $table_name . '_phenotype';
+//   if (chado_table_exists($phenotype_table)) {
+//     $field_name = 'sbo__phenotype';
+//     $field_type = 'sbo__phenotype';
+//     $info[$field_name] = array(
+//       'field_name' => $field_name,
+//       'type' => $field_type,
+//       'cardinality' => FIELD_CARDINALITY_UNLIMITED,
+//       'locked' => FALSE,
+//       'storage' => array(
+//         'type' => 'field_chado_storage',
+//       ),
+//     );
+//   }
 
   // PROPERTIES
   $prop_table = $table_name . 'prop';
@@ -732,8 +730,8 @@ function tripal_chado_bundle_instances_info_base(&$info, $entity_type, $bundle,
     // have a special field for those.
     if ($table_name == 'organism' and ($column_name == 'type_id' or
         $column_name == 'infraspecific_name')) {
-          continue;
-        }
+      continue;
+    }
 
     // Don't create base fields for the primary key and the type_id field.
     if ($column_name == $pkey or $column_name == $type_column) {
@@ -753,7 +751,7 @@ function tripal_chado_bundle_instances_info_base(&$info, $entity_type, $bundle,
       continue;
     }
 
-    $field_name = strtolower($cvterm->dbxref_id->db_id->name . '__' . preg_replace('/ /', '_', $cvterm->name));
+    $field_name = strtolower($cvterm->dbxref_id->db_id->name . '__' . preg_replace('/[^\w]/', '_', $cvterm->name));
     $field_name = substr($field_name, 0, 32);
 
     // Skip the primary key field.
@@ -761,8 +759,9 @@ function tripal_chado_bundle_instances_info_base(&$info, $entity_type, $bundle,
       continue;
     }
 
-    // Skip the type field.
-    if ($table_name == $type_table and $column_name == $type_column) {
+    // If the type_id defines the content type and it's part of the
+    // base table and this column is the type_id then skip it.
+    if (!$type_table and $type_column and $column_name == $type_column) {
       continue;
     }
 
@@ -856,46 +855,87 @@ function tripal_chado_bundle_instances_info_base(&$info, $entity_type, $bundle,
         unset($base_info['settings']['format']);
       }
     }
-    elseif ($base_info['label'] == 'Timeaccessioned') {
+    if ($base_info['label'] == 'Timeaccessioned') {
       $base_info['label'] = 'Time Accessioned';
       $base_info['description'] = 'Please enter the time that this record was first added to the database.';
     }
-    elseif ($base_info['label'] == 'Timelastmodified') {
+    if ($base_info['label'] == 'Timelastmodified') {
       $base_info['label'] = 'Time Last Modified';
       $base_info['description'] = 'Please enter the time that this record was last modified. The default is the current time.';
     }
     //
     // ORGANISM TABLE
     //
-    elseif ($table_name == 'organism' and $column_name == 'comment') {
+    if ($table_name == 'organism' and $column_name == 'comment') {
       $base_info['label'] = 'Description';
     }
     //
     // PUB TABLE
     //
-    elseif ($table_name == 'pub' and $column_name == 'uniquename') {
-      $base_info['widget_type'] = 'text_textfield';
+    if ($table_name == 'pub') {
+      if ($column_name == 'title' or $column_name == 'type_id') {
+        $base_info['required'] = TRUE;
+      }
+      if($column_name == 'uniquename' or $column_name == 'title' or $column_name == 'volumetitle') {
+        $base_info['widget']['type'] = 'text_textfield';
+        $base_info['settings']['text_processing'] = '0';
+      }
+      if($column_name == 'uniquename') {
+        $base_info['label'] = 'Unique Local Identifier';
+        $base_info['required'] = TRUE;
+        $base_info['description'] = 'This publication is housed in Chado whic requires a unique identifer (or name) be provided for every publication. This identifier need not be shown to end-users but it is required. Each site must decide on a format for this unique name.';
+      }
+      if($column_name == 'title') {
+        $base_info['description'] = 'The title of the published work.';
+      }
+      if($column_name == 'series_name') {
+        $base_info['description'] = 'The name media that produces a series of publications (e.g. journal, conference proceedings, etc.).';
+      }
+      if($column_name == 'issue') {
+        $base_info['description'] = 'The issue of the series (e.g. journal) where the publication was printed.';
+      }
+      if($column_name == 'volume') {
+        $base_info['description'] = 'The volume of the series (e.g. journal) where the publication was printed.';
+      }
+      if($column_name == 'pyear') {
+        $base_info['label'] = 'Publication Year';
+        $base_info['required'] = TRUE;
+      }
+      if($column_name == 'pages') {
+        $base_info['label'] = 'Page Numbers';
+      }
+      if($column_name == 'pubplace') {
+        $base_info['label'] = 'Publication Location';
+      }
+      if($column_name == 'volumetitle') {
+        $base_info['label'] = 'Volumn Title';
+        $base_info['label'] = 'The title of the volume (if applicable).';
+      }
+      if($column_name == 'miniref') {
+        $base_info['label'] = 'Mini Local identifier';
+        $base_info['description'] = 'Some sites use small identifiers for each publication. if your site uses this please provide the proper miniref for this publication.';
+      }
     }
 
     //
     // ANALYSIS TABLE
     //
-    elseif ($table_name == 'analysis' and $column_name == 'name') {
+    if ($table_name == 'analysis' and $column_name == 'name') {
       $base_info['required'] = TRUE;
     }
-    elseif ($table_name == 'analysis' and $column_name == 'program') {
+    if ($table_name == 'analysis' and $column_name == 'program') {
       $base_info['description'] = 'The program name (e.g. blastx, blastp, sim4, genscan. If the analysis was not derived from a software package then provide a very brief description of the pipeline, workflow or method.';
       $base_info['label'] = 'Program, Pipeline, Workflow or Method Name';
     }
-    elseif ($table_name == 'analysis' and $column_name == 'algorithm') {
+    if ($table_name == 'analysis' and $column_name == 'algorithm') {
       $base_info['label'] = 'Source Version';
       $base_info['description'] = 'The name of the algorithm used to produce the dataset if different from the program.';
     }
-    elseif ($table_name == 'analysis' and $column_name == 'programversion') {
+    if ($table_name == 'analysis' and $column_name == 'programversion') {
       $base_info['label'] = 'Program Version';
       $base_info['description'] = 'The version of the program used to perform this analysis. (e.g. TBLASTX 2.0MP-WashU [09-Nov-2000]. Enter "n/a" if no version is available or applicable.';
     }
-    elseif ($table_name == 'analysis' and $column_name == 'timeexecuted') {
+    if ($table_name == 'analysis' and $column_name == 'timeexecuted') {
       $base_info['label'] = 'Date Performed';
       $base_info['description'] = 'The date and time when the analysis was performed.';
     }
@@ -909,7 +949,7 @@ function tripal_chado_bundle_instances_info_base(&$info, $entity_type, $bundle,
     //
     // PROJECT TABLE
     //
-    elseif ($table_name == 'project' and $column_name == 'description') {
+    if ($table_name == 'project' and $column_name == 'description') {
       $base_info['label'] = 'Short Description';
     }
     $info[$field_name] = $base_info;
@@ -934,12 +974,8 @@ function tripal_chado_bundle_instances_info_custom(&$info, $entity_type, $bundle
   $type_value = $details['chado_type_value'];
   $schema = chado_get_schema($table_name);
 
-  // BASE TYPE_ID
-  // Exclude the type_id field on base tables where content types are mapped
-  // by the type_id field or on the organism table where the type_id is mean
-  // as an infraspecific name type.
-  if (array_key_exists('type_id', $schema['fields']) and
-      $table_name != 'organism' and $type_column != 'type_id') {
+  // An additional type for publications
+  if ($table_name == 'pub') {
     $field_name = 'schema__additional_type';
     $is_required = FALSE;
     if (array_key_exists('not null', $schema['fields']['type_id']) and
@@ -950,14 +986,16 @@ function tripal_chado_bundle_instances_info_custom(&$info, $entity_type, $bundle
       'field_name' => $field_name,
       'entity_type' => $entity_type,
       'bundle' => $bundle->name,
-      'label' => 'Type',
-      'description' => 'Select a type for this record.',
+      'label' => 'Publication Type',
+      'description' => 'Select the publication type.',
       'required' => $is_required,
       'settings' => array(
         'auto_attach' => TRUE,
         'chado_table' => $table_name,
         'chado_column' => 'type_id',
         'base_table' => $table_name,
+        'vocabulary' => 'tripal_pub',
+        'parent_term' => 'TPUB:0000015',
       ),
       'widget' => array(
         'type' => 'schema__additional_type_widget',
@@ -1245,38 +1283,38 @@ function tripal_chado_bundle_instances_info_custom(&$info, $entity_type, $bundle
   }
 
 
-  // GENE TRANSCRIPTS
-  $rel_table = $table_name . '_relationship';
-  if (chado_table_exists($rel_table) and $bundle->label == 'gene') {
-    $field_name = 'so__transcript';
-    $info[$field_name] = array(
-      'field_name' => $field_name,
-      'entity_type' => $entity_type,
-      'bundle' => $bundle->name,
-      'label' => 'Transcripts',
-      'description' => 'Transcripts that are part of this gene.',
-      'required' => FALSE,
-      'settings' => array(
-        'auto_attach' => FALSE,
-        'chado_table' => $rel_table,
-        'chado_column' => '',
-        'base_table' => $table_name,
-      ),
-      'widget' => array(
-        'type' => 'so__transcript_widget',
-        'settings' => array(
-          'display_label' => 1,
-        ),
-      ),
-      'display' => array(
-        'default' => array(
-          'label' => 'above',
-          'type' => 'so__transcript_formatter',
-          'settings' => array(),
-        ),
-      ),
-    );
-  }
+//   // GENE TRANSCRIPTS
+//   $rel_table = $table_name . '_relationship';
+//   if (chado_table_exists($rel_table) and $bundle->label == 'gene') {
+//     $field_name = 'so__transcript';
+//     $info[$field_name] = array(
+//       'field_name' => $field_name,
+//       'entity_type' => $entity_type,
+//       'bundle' => $bundle->name,
+//       'label' => 'Transcripts',
+//       'description' => 'Transcripts that are part of this gene.',
+//       'required' => FALSE,
+//       'settings' => array(
+//         'auto_attach' => FALSE,
+//         'chado_table' => $rel_table,
+//         'chado_column' => '',
+//         'base_table' => $table_name,
+//       ),
+//       'widget' => array(
+//         'type' => 'so__transcript_widget',
+//         'settings' => array(
+//           'display_label' => 1,
+//         ),
+//       ),
+//       'display' => array(
+//         'default' => array(
+//           'label' => 'above',
+//           'type' => 'so__transcript_formatter',
+//           'settings' => array(),
+//         ),
+//       ),
+//     );
+//   }
 
   // ORGANISM TYPE_ID
   if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
@@ -1588,75 +1626,75 @@ function tripal_chado_bundle_instances_info_linker(&$info, $entity_type, $bundle
     );
   }
 
-  // GENOTYPE
-  $genotype_table = $table_name . '_genotype';
-  if (chado_table_exists($genotype_table)) {
-    $field_name = 'so__genotype';
-    $schema = chado_get_schema($genotype_table);
-    $pkey = $schema['primary key'][0];
-    $info[$field_name] = array(
-      'field_name' => $field_name,
-      'entity_type' => $entity_type,
-      'bundle' => $bundle->name,
-      'label' => 'Genotype',
-      'description' => 'The genotypes associated with this record.',
-      'required' => FALSE,
-      'settings' => array(
-        'auto_attach' => FALSE,
-        'chado_table' => $genotype_table,
-        'chado_column' => $pkey,
-        'base_table' => $table_name,
-      ),
-      'widget' => array(
-        'type' => 'so__genotype_widget',
-        'settings' => array(
-          'display_label' => 1,
-        ),
-      ),
-      'display' => array(
-        'default' => array(
-          'label' => 'hidden',
-          'type' => 'so__genotype_formatter',
-          'settings' => array(),
-        ),
-      ),
-    );
-  }
+//   // GENOTYPE
+//   $genotype_table = $table_name . '_genotype';
+//   if (chado_table_exists($genotype_table)) {
+//     $field_name = 'so__genotype';
+//     $schema = chado_get_schema($genotype_table);
+//     $pkey = $schema['primary key'][0];
+//     $info[$field_name] = array(
+//       'field_name' => $field_name,
+//       'entity_type' => $entity_type,
+//       'bundle' => $bundle->name,
+//       'label' => 'Genotype',
+//       'description' => 'The genotypes associated with this record.',
+//       'required' => FALSE,
+//       'settings' => array(
+//         'auto_attach' => FALSE,
+//         'chado_table' => $genotype_table,
+//         'chado_column' => $pkey,
+//         'base_table' => $table_name,
+//       ),
+//       'widget' => array(
+//         'type' => 'so__genotype_widget',
+//         'settings' => array(
+//           'display_label' => 1,
+//         ),
+//       ),
+//       'display' => array(
+//         'default' => array(
+//           'label' => 'hidden',
+//           'type' => 'so__genotype_formatter',
+//           'settings' => array(),
+//         ),
+//       ),
+//     );
+//   }
 
-  // PHENOTYPE
-  $phenotype_table = $table_name . '_phenotype';
-  if (chado_table_exists($phenotype_table)) {
-    $field_name = 'sbo__phenotype';
-    $schema = chado_get_schema($phenotype_table);
-    $pkey = $schema['primary key'][0];
-    $info[$field_name] = array(
-      'field_name' => $field_name,
-      'entity_type' => $entity_type,
-      'bundle' => $bundle->name,
-      'label' => 'Phenotype',
-      'description' => 'The phenotypes associated with this record.',
-      'required' => FALSE,
-      'settings' => array(
-        'auto_attach' => FALSE,
-        'chado_table' => $phenotype_table,
-        'chado_column' => $pkey,
-        'base_table' => $table_name,
-      ),
-      'widget' => array(
-        'type' => 'sbo__phenotype_widget',
-        'settings' => array(
-          'display_label' => 1,
-        ),
-      ),
-      'display' => array(
-        'default' => array(
-          'label' => 'hidden',
-          'type' => 'sbo__phenotype_formatter',
-          'settings' => array(),
-        ),
-      ),
-    );
-  }
+//   // PHENOTYPE
+//   $phenotype_table = $table_name . '_phenotype';
+//   if (chado_table_exists($phenotype_table)) {
+//     $field_name = 'sbo__phenotype';
+//     $schema = chado_get_schema($phenotype_table);
+//     $pkey = $schema['primary key'][0];
+//     $info[$field_name] = array(
+//       'field_name' => $field_name,
+//       'entity_type' => $entity_type,
+//       'bundle' => $bundle->name,
+//       'label' => 'Phenotype',
+//       'description' => 'The phenotypes associated with this record.',
+//       'required' => FALSE,
+//       'settings' => array(
+//         'auto_attach' => FALSE,
+//         'chado_table' => $phenotype_table,
+//         'chado_column' => $pkey,
+//         'base_table' => $table_name,
+//       ),
+//       'widget' => array(
+//         'type' => 'sbo__phenotype_widget',
+//         'settings' => array(
+//           'display_label' => 1,
+//         ),
+//       ),
+//       'display' => array(
+//         'default' => array(
+//           'label' => 'hidden',
+//           'type' => 'sbo__phenotype_formatter',
+//           'settings' => array(),
+//         ),
+//       ),
+//     );
+//   }
 
   // PROPERTIES
   $prop_table = $table_name . 'prop';
@@ -1728,6 +1766,7 @@ function tripal_chado_bundle_instances_info_linker(&$info, $entity_type, $bundle
        while ($prop = $props->fetchObject()) {
 
          $term = chado_generate_var('cvterm', array('cvterm_id' => $prop->type_id));
+         $term = chado_expand_var($term, 'field', 'cvterm.definition');
 
          // The tripal_analysis_KEGG, tripal_analysis_blast, and
          // tripal_analysis_interpro modules store results in the analysisprop

+ 2 - 4
tripal_chado/includes/tripal_chado.publish.inc

@@ -2,8 +2,7 @@
 
 function tripal_chado_publish_form($form, &$form_state) {
 
-  global $language;
-  $langcode = $language->language;
+  $langcode = 'und';
 
   $bundle_name = '';
   if (array_key_exists('values', $form_state)) {
@@ -141,9 +140,8 @@ function tripal_chado_publish_form_validate($form, &$form_state) {
 function tripal_chado_publish_form_submit($form, &$form_state) {
   if ($form_state['clicked_button']['#name'] == 'publish_btn') {
     global $user;
-    global $language;
 
-    $langcode = $language->language;
+    $langcode = 'und';
 
     $bundle_name = $form_state['values']['bundle_name'];
     $bundle = tripal_load_bundle_entity(array('name' => $bundle_name));

+ 8 - 1
tripal_chado/includes/tripal_chado.semweb.inc

@@ -202,7 +202,7 @@ function tripal_chado_populate_vocab_SCHEMA() {
     'cv_name' => 'schema',
     'definition' => 'URL of the item.',
   ));
-  tripal_associate_chado_semweb_term('db', 'URL', $term);
+  tripal_associate_chado_semweb_term('db', 'url', $term);
 
   // Typically the type_id field is used for distinguishing between records
   // but in the case that it isn't then we need to associate a term with it
@@ -890,6 +890,13 @@ function tripal_chado_populate_vocab_LOCAL() {
   ));
   tripal_associate_chado_semweb_term(NULL, 'is_obsolete', $term);
 
+  $term = tripal_insert_cvterm(array(
+    'id' => 'local:miniref',
+    'name' => 'Mini-ref',
+    'definition' => 'A small in-house unique identifier for a publication.',
+    'cv_name' => 'local',
+  ));
+  tripal_associate_chado_semweb_term('pub', 'miniref', $term);
 
   //-----------------------------
   // Relationship Terms

+ 26 - 0
tripal_chado/tripal_chado.install

@@ -1159,4 +1159,30 @@ function tripal_chado_update_7311() {
     $error = $e->getMessage();
     throw new DrupalUpdateException('Could not perform update: '. $error);
   }
+}
+/**
+ * Associates a local term with the pub.miniref column.
+ */
+function tripal_chado_update_7312() {
+  try {
+
+    $term = tripal_insert_cvterm(array(
+      'id' => 'local:miniref',
+      'name' => 'Mini-ref',
+      'definition' => 'A small in-house unique identifier for a publication.',
+      'cv_name' => 'local',
+    ));
+    tripal_associate_chado_semweb_term('pub', 'miniref', $term);
+    $term = tripal_insert_cvterm(array(
+      'id' => 'schema:url',
+      'name' => 'url',
+      'cv_name' => 'schema',
+      'definition' => 'URL of the item.',
+    ));
+    tripal_associate_chado_semweb_term('db', 'url', $term);
+  }
+  catch (\PDOException $e) {
+    $error = $e->getMessage();
+    throw new DrupalUpdateException('Could not perform update: '. $error);
+  }
 }