瀏覽代碼

Merge branch '7.x-3.x' of github.com:tripal/tripal into 7.x-3.x

Chun-Huai Cheng 7 年之前
父節點
當前提交
f5fe29f584
共有 30 個文件被更改,包括 712 次插入460 次删除
  1. 5 0
      tripal/includes/TripalFields/TripalField.inc
  2. 1 1
      tripal/tripal_views_query.inc
  3. 32 16
      tripal_chado/api/modules/tripal_chado.pub.api.inc
  4. 2 0
      tripal_chado/includes/TripalFields/chado_linker__prop/chado_linker__prop.inc
  5. 3 0
      tripal_chado/includes/TripalFields/chado_linker__prop/chado_linker__prop_widget.inc
  6. 0 6
      tripal_chado/includes/TripalFields/data__accession/data__accession_widget.inc
  7. 2 2
      tripal_chado/includes/TripalFields/sbo__phenotype/sbo__phenotype.inc
  8. 38 1
      tripal_chado/includes/TripalFields/schema__additional_type/schema__additional_type.inc
  9. 8 5
      tripal_chado/includes/TripalFields/schema__additional_type/schema__additional_type_formatter.inc
  10. 80 1
      tripal_chado/includes/TripalFields/schema__additional_type/schema__additional_type_widget.inc
  11. 36 13
      tripal_chado/includes/TripalFields/schema__alternate_name/schema__alternate_name.inc
  12. 3 2
      tripal_chado/includes/TripalFields/schema__alternate_name/schema__alternate_name_formatter.inc
  13. 53 34
      tripal_chado/includes/TripalFields/schema__alternate_name/schema__alternate_name_widget.inc
  14. 0 43
      tripal_chado/includes/TripalFields/schema__publication/schema__publication.inc
  15. 2 7
      tripal_chado/includes/TripalFields/schema__publication/schema__publication_formatter.inc
  16. 37 31
      tripal_chado/includes/TripalFields/schema__publication/schema__publication_widget.inc
  17. 12 52
      tripal_chado/includes/TripalFields/sio__annotation/sio__annotation.inc
  18. 0 30
      tripal_chado/includes/TripalFields/sio__references/sio__references.inc
  19. 29 2
      tripal_chado/includes/TripalFields/sio__vocabulary/sio__vocabulary_widget.inc
  20. 0 7
      tripal_chado/includes/TripalFields/so__genotype/so__genotype.inc
  21. 5 0
      tripal_chado/includes/TripalFields/uo__unit/uo__unit.inc
  22. 42 1
      tripal_chado/includes/TripalFields/uo__unit/uo__unit_widget.inc
  23. 14 12
      tripal_chado/includes/setup/tripal_chado.setup.inc
  24. 2 2
      tripal_chado/includes/tripal_chado.field_storage.inc
  25. 241 181
      tripal_chado/includes/tripal_chado.fields.inc
  26. 2 4
      tripal_chado/includes/tripal_chado.publish.inc
  27. 8 1
      tripal_chado/includes/tripal_chado.semweb.inc
  28. 42 0
      tripal_chado/tripal_chado.install
  29. 0 1
      tripal_ds/tripal_ds.install
  30. 13 5
      tripal_ws/includes/TripalWebService/TripalEntityService_v0_1.inc

+ 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 - 1
tripal/tripal_views_query.inc

@@ -233,7 +233,7 @@ class tripal_views_query extends views_plugin_query {
 
         // Get the IDs
         $results = $query->execute();
-        $entity_ids = array_keys($results['TripalEntity']);
+        $entity_ids = (isset($results['TripalEntity']) AND is_array($results['TripalEntity'])) ? array_keys($results['TripalEntity']) : array();
 
         $this->pager->post_execute($view->result);
         if ($this->pager->use_count_query() || !empty($view->get_total_rows)) {

+ 32 - 16
tripal_chado/api/modules/tripal_chado.pub.api.inc

@@ -302,7 +302,8 @@ function tripal_autocomplete_pub($string = '') {
   ";
   $pubs = chado_query($sql, array(':str' => $string . '%'));
   while ($pub = $pubs->fetchObject()) {
-    $items[$pub->uniquename] = $pub->uniquename;
+    $val = $pub->title  . " [id:" . $pub->pub_id . "]";
+    $items[$val] = $pub->title;
   }
 
   drupal_json_output($items);
@@ -1025,21 +1026,6 @@ function tripal_get_minimal_pub_info($pub) {
   $pub = chado_expand_var($pub, 'field', 'pub.title');
   $pub = chado_expand_var($pub, 'field', 'pub.volumetitle');
 
-  // get the citation
-  $values = array(
-    'pub_id' => $pub->pub_id,
-    'type_id' => array(
-      'name' => 'Citation',
-    ),
-  );
-  $options = array(
-    'include_fk' => array(
-    ),
-  );
-  $citation = chado_generate_var('pubprop', $values, $options);
-  $citation = chado_expand_var($citation, 'field', 'pubprop.value');
-  $citation = $citation->value;
-
   // get the abstract
   $values = array(
     'pub_id' => $pub->pub_id,
@@ -1121,6 +1107,36 @@ function tripal_get_minimal_pub_info($pub) {
     $dbxrefs[] = $pub_dbxref->dbxref_id->db_id->name . ':' . $pub_dbxref->dbxref_id->accession;
   }
 
+  // get the citation
+  $values = array(
+    'pub_id' => $pub->pub_id,
+    'type_id' => array(
+      'name' => 'Citation',
+    ),
+  );
+  $options = array(
+    'include_fk' => array(
+    ),
+  );
+  $citation = chado_generate_var('pubprop', $values, $options);
+  if ($citation) {
+    $citation = chado_expand_var($citation, 'field', 'pubprop.value');
+    $citation = $citation->value;
+  }
+  else {
+    $pub_info = array(
+      'Title' => $pub->title,
+      'Publication Type' => $pub->type_id->name,
+      'Authors' => $authors_list,
+      'Series Name' => $pub->series_name,
+      'Volume' => $pub->volume,
+      'Issue' => $pub->issue,
+      'Pages' => $pub->pages,
+      'Publication Date' => $pub->pyear,
+    );
+    $citation = tripal_pub_create_citation($pub_info);
+  }
+
   return array(
     'TPUB:0000039' => $pub->title,
     'TPUB:0000003' => $citation,

+ 2 - 0
tripal_chado/includes/TripalFields/chado_linker__prop/chado_linker__prop.inc

@@ -41,6 +41,8 @@ class chado_linker__prop extends ChadoField {
     'chado_column' => '',
     // The base table.
     'base_table' => '',
+    // The number of default rows to show. The default is 1.
+    'rows' => 1,
   );
 
   // The default widget for this field.

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

@@ -19,6 +19,7 @@ class chado_linker__prop_widget extends ChadoFieldWidget {
     $base_table = $this->instance['settings']['base_table'];
     $field_table = $this->instance['settings']['chado_table'];
     $chado_column = $this->instance['settings']['chado_column'];
+    $rows = array_key_exists('rows', $this->instance['settings']) ? $this->instance['settings']['rows'] : 1;
     $instance = $this->instance;
 
     // Get the name of the pkey field for this property table and the name
@@ -94,6 +95,8 @@ class chado_linker__prop_widget extends ChadoFieldWidget {
       '#default_value' => $value,
       '#title' => $instance['label'],
       '#description' => $instance['description'],
+      '#rows' => $rows,
+      '#required' => $instance['required'],
     );
     $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,
       ),
     );
   }

+ 38 - 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,36 @@ 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) {
+    $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 +95,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;
+    }
   }
 }

+ 36 - 13
tripal_chado/includes/TripalFields/schema__alternate_name/schema__alternate_name.inc

@@ -59,9 +59,6 @@ class schema__alternate_name extends ChadoField {
     // Get the PKey for this table
     $schema = chado_get_schema($field_table);
     $pkey = $schema['primary key'][0];
-
-    // Get the FK that links to the base record.
-    $schema = chado_get_schema($field_table);
     $fkey_lcolumn = key($schema['foreign keys'][$base_table]['columns']);
     $fkey_rcolumn = $schema['foreign keys'][$base_table]['columns'][$fkey_lcolumn];
 
@@ -106,18 +103,44 @@ class schema__alternate_name extends ChadoField {
    * @see ChadoField::query()
    */
   public function query($query, $condition) {
-    $syn_linker = $this->instance['settings']['chado_table'];
-    $base_table = $this->instance['settings']['base_table'];
-    $bschema = chado_get_schema($base_table);
-    $bpkey = $bschema['primary key'][0];
-    $alias = 'syn_linker';
+    $alias = $this->field['field_name'];
     $operator = $condition['operator'];
 
-    if ($condition['column'] == 'alternatename') {
-      $this->queryJoinOnce($query, $syn_linker, $alias, "base.$bpkey = $alias.$bpkey");
-      $this->queryJoinOnce($query, 'synonym', 'SYN', "SYN.synonym_id = $alias.synonym_id");
-      $query->condition("SYN.name", $condition['value']);
-    }
+    $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'];
+    $base_table = $this->instance['settings']['base_table'];
+
+    $schema = chado_get_schema($field_table);
+    $pkey = $schema['primary key'][0];
+    $fkey_lcolumn = key($schema['foreign keys'][$base_table]['columns']);
+    $fkey_rcolumn = $schema['foreign keys'][$base_table]['columns'][$fkey_lcolumn];
+
+    $this->queryJoinOnce($query, $field_table, $alias, "base.$fkey_rcolumn = $alias.$fkey_lcolumn");
+    $this->queryJoinOnce($query, 'synonym', $alias . '_SYN', $alias . "_SYN.synonym_id = $alias.synonym_id");
+    $query->condition($alias . "_SYN.name", $condition['value']);
   }
 
+  /**
+   * @see ChadoField::query()
+   */
+  public function queryOrder($query, $order) {
+    $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'];
+    $base_table = $this->instance['settings']['base_table'];
+
+    $schema = chado_get_schema($field_table);
+    $pkey = $schema['primary key'][0];
+    $fkey_lcolumn = key($schema['foreign keys'][$base_table]['columns']);
+    $fkey_rcolumn = $schema['foreign keys'][$base_table]['columns'][$fkey_lcolumn];
+
+    $this->queryJoinOnce($query, $field_table, $alias, "base.$fkey_rcolumn = $alias.$fkey_lcolumn", "LEFT OUTER");
+    $this->queryJoinOnce($query, 'synonym', $alias . '_SYN', $alias . "_SYN.synonym_id = $alias.synonym_id", "LEFT OUTER");
+    $query->orderBy($alias . "_SYN.name", $order['direction']);
+  }
 }

+ 3 - 2
tripal_chado/includes/TripalFields/schema__alternate_name/schema__alternate_name_formatter.inc

@@ -13,15 +13,16 @@ class schema__alternate_name_formatter extends ChadoFieldFormatter {
    */
   public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
     $list_items = array();
+
     foreach ($items as $delta => $item) {
       $list_items[] = $item['value'];
     }
     $list = 'There are no synonyms.';
-    if (count($list_items) > 1) {
+    if (count($list_items) > 0) {
       $list = array(
         'title' => '',
         'items' => $list_items,
-        'type' => 'ol',
+        'type' => 'ul',
         'attributes' => array(),
       );
       $list = theme_item_list($list);

+ 53 - 34
tripal_chado/includes/TripalFields/schema__alternate_name/schema__alternate_name_widget.inc

@@ -13,7 +13,6 @@ class schema__alternate_name_widget extends ChadoFieldWidget {
    */
   public function form(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
     parent::form($widget, $form, $form_state, $langcode, $items, $delta, $element);
-
     $field_name = $this->field['field_name'];
 
     // Get the FK column that links to the base table.
@@ -26,7 +25,7 @@ class schema__alternate_name_widget extends ChadoFieldWidget {
 
     // Get the field defaults.
     $record_id = '';
-    $fkey_value = array_key_exists('#entity', $element) and $element['#entity'] ? $element['#entity']->chado_record_id : NULL;
+    $fkey_value = (array_key_exists('#entity', $element) and $element['#entity']) ? $element['#entity']->chado_record_id : NULL;
     $synonym_id = '';
     $pub_id = '';
     $is_current = TRUE;
@@ -49,7 +48,6 @@ class schema__alternate_name_widget extends ChadoFieldWidget {
     // Check $form_state['values'] to see if an AJAX call set the values.
     if (array_key_exists('values', $form_state) and
         array_key_exists($field_name, $form_state['values'])) {
-      $record_id = $form_state['values'][$field_name]['und'][$delta]['chado-' . $table_name . '__' . $pkey];
       $synonym_id = $form_state['values'][$field_name]['und'][$delta]['chado-' . $table_name . '__synonym_id'];
       $pub_id = $form_state['values'][$field_name]['und'][$delta]['chado-' . $table_name . '__pub_id'];
       $is_current = $form_state['values'][$field_name]['und'][$delta]['chado-' . $table_name . '__is_current'];
@@ -72,10 +70,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 +123,10 @@ class schema__alternate_name_widget extends ChadoFieldWidget {
       '#required' => $element['#required'],
     );
   }
-
   /**
-   *
-   * @see TripalFieldWidget::submit()
+   * @see TripalFieldWidget::validate()
    */
-  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 +138,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'][$delta]['value'] = $synonym->name;
+        $form_state['values'][$field_name]['und'][$delta]['chado-' . $table_name . '__synonym_id'] = $synonym->synonym_id;
+      }
+      else {
+        $form_state['values'][$field_name]['und'][$delta]['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 +200,9 @@ class schema__alternate_name_widget extends ChadoFieldWidget {
           'synonym_sgml' => '',
         ));
         $synonym = (object) $synonym;
+        $form_state['values'][$field_name]['und'][$delta]['value'] = $synonym->name;
+        $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 +214,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 - 43
tripal_chado/includes/TripalFields/schema__publication/schema__publication.inc

@@ -94,7 +94,6 @@ class schema__publication extends ChadoField {
       'chado-' . $field_table . '__' . $pkey => '',
       'chado-' . $field_table . '__' . $fkey_lcolumn => '',
       'chado-' . $field_table . '__' . 'pub_id' => '',
-      'uniquename' => '',
     );
 
     $linker_table = $base_table . '_pub';
@@ -112,7 +111,6 @@ class schema__publication extends ChadoField {
         $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__' . $pkey] = $linker->$pkey;
         $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__' . $fkey_lcolumn] = $linker->$fkey_lcolumn->$fkey_lcolumn;
         $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__' . 'pub_id'] = $pub->pub_id;
-        $entity->{$field_name}['und'][$i]['uniquename'] =  $pub->uniquename;
 
         if (property_exists($pub, 'entity_id')) {
           $entity->{$field_name}['und'][$i]['value']['entity'] = 'TripalEntity:' . $pub->entity_id;
@@ -121,45 +119,4 @@ class schema__publication extends ChadoField {
       }
     }
   }
-
-  /**
-   * @see ChadoField::query()
-   */
-  public function query($query, $condition) {
-    $pub_linker = $this->instance['settings']['chado_table'];
-    $base_table = $this->instance['settings']['base_table'];
-    $bschema = chado_get_schema($base_table);
-    $bpkey = $bschema['primary key'][0];
-    $alias = 'pub_linker';
-    $operator = $condition['operator'];
-
-    if ($condition['column'] == 'publication.database_cross_reference') {
-      list($db_name, $accession) = explode(':', $condition['value']);
-
-      $this->queryJoinOnce($query, $pub_linker, $alias, "base.$bpkey = $alias.$bpkey");
-      $this->queryJoinOnce($query, 'pub_dbxref', 'PDBX', "PDBX.pub_id = $alias.pub_id");
-      $this->queryJoinOnce($query, 'dbxref', 'DBX', "DBX.dbxref_id = PDBX.dbxref_id");
-      $this->queryJoinOnce($query, 'db', 'DB', "DB.db_id = DBX.db_id");
-      $query->condition("DB.name", $db_name);
-      $query->condition("DBX.accession", $accession);
-    }
-
-    if ($condition['column'] == 'publication.title') {
-      $this->queryJoinOnce($query, $pub_linker, $alias, "base.$bpkey = $alias.$bpkey");
-      $this->queryJoinOnce($query, 'pub', 'PUB', "PUB.pub_id = $alias.pub_id");
-      $query->condition('PUB.title', $condition['value'], $operator);
-    }
-
-    if ($condition['column'] == 'publication.citation') {
-
-    }
-
-    if ($condition['column'] == 'publication.authors') {
-
-    }
-    if ($condition['column'] == 'publication.abstract') {
-
-    }
-  }
-
 }

+ 2 - 7
tripal_chado/includes/TripalFields/schema__publication/schema__publication_formatter.inc

@@ -17,19 +17,14 @@ class schema__publication_formatter extends ChadoFieldFormatter {
 
     foreach ($items as $delta => $item) {
 
-      if (empty($item['value'])) {
-        continue;
-      }
       $title = isset($item['value']['TPUB:0000039']) ? $item['value']['TPUB:0000039'] : '';
       $citation = isset($item['value']['TPUB:0000003']) ? $item['value']['TPUB:0000003'] : '';
       $entity = array_key_exists('entity', $item['value']) ? $item['value']['entity'] : '';
       if ($entity) {
         list($entity_type, $entity_id) = explode(':', $entity);
         $new_title = l($title, 'bio_data/' . $entity_id);
-        // If a title has parens we need to escape them for the
-        // regular expression to work.
-        $title = preg_replace('/\(/', '\(', $title);
-        $title = preg_replace('/\)/', '\)', $title);
+        // Escape anything that isn't alphanumeric
+        $title = preg_replace('/([^\w])/', '\\\\$1', $title);
         $citation = preg_replace("/$title/", $new_title, $citation);
       }
       $list_items[] = $citation;

+ 37 - 31
tripal_chado/includes/TripalFields/schema__publication/schema__publication_widget.inc

@@ -25,15 +25,28 @@ class schema__publication_widget extends ChadoFieldWidget {
     $fkey = $fkeys[0];
 
     // Get the field defaults.
-    $fkey_value = (array_key_exists('#entity', $element) and is_object($element['#entity'])) ? $element['#entity']->chado_record_id : NULL;
+    $pkey_val = '';
+    $fkey_value = '';
     $pub_id = '';
-    $uname = '';
+    $title = '';
 
     // If the field already has a value then it will come through the $items
     // array.  This happens when editing an existing record.
     if (count($items) > 0 and array_key_exists($delta, $items)) {
+      $pkey_val =  tripal_get_field_item_keyval($items, $delta, 'chado-' . $table_name . '__' . $pkey, $pkey_val);
+      $fkey_value = tripal_get_field_item_keyval($items, $delta, 'chado-' . $table_name . '__' . $fkey, $fkey_value);
       $pub_id = tripal_get_field_item_keyval($items, $delta, 'chado-' . $table_name . '__pub_id', $pub_id);
-      $uname = tripal_get_field_item_keyval($items, $delta, 'uniquename', $uname);
+      if ($pub_id) {
+        $pub = tripal_get_publication(array('pub_id' => $pub_id));
+        $title =  $pub->title . ' [id:' . $pub->pub_id . ']';
+      }
+    }
+
+    // Check $form_state['values'] to see if an AJAX call set the values.
+    if (array_key_exists('values', $form_state) and
+        array_key_exists($field_name, $form_state['values'])) {
+      $title = $form_state['values'][$field_name]['und'][$delta]['pub_title'];
+      $pub_id = $form_state['values'][$field_name]['und'][$delta]['accession'];
     }
 
     $schema = chado_get_schema('pub');
@@ -50,7 +63,7 @@ class schema__publication_widget extends ChadoFieldWidget {
 
     $widget['chado-' . $table_name . '__' . $pkey] = array(
       '#type' => 'value',
-      '#default_value' => '',
+      '#default_value' => $pkey_val,
     );
     $widget['chado-' . $table_name . '__' . $fkey] = array(
       '#type' => 'value',
@@ -61,17 +74,11 @@ class schema__publication_widget extends ChadoFieldWidget {
       '#default_value' => $pub_id,
     );
 
-    $widget['uniquename'] = array(
+    $widget['pub_title'] = array(
       '#type' => 'textfield',
       '#title' => t('Publication'),
-      '#default_value' => $uname,
+      '#default_value' => $title,
       '#autocomplete_path' => 'admin/tripal/storage/chado/auto_name/pub',
-      '#ajax' => array(
-        'callback' => "schema__publication_widget_form_ajax_callback",
-        'wrapper' => "$table_name-$delta",
-        'effect' => 'fade',
-        'method' => 'replace'
-      ),
       '#maxlength' => 100000,
     );
   }
@@ -81,7 +88,7 @@ class schema__publication_widget extends ChadoFieldWidget {
    *
    * @see TripalFieldWidget::submit()
    */
-  public function submit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
+  public function validate($element, $form, &$form_state, $langcode, $delta) {
     // Get the FK column that links to the base table.
     $table_name = $this->instance['settings']['chado_table'];
     $base_table = $this->instance['settings']['base_table'];
@@ -92,31 +99,30 @@ class schema__publication_widget extends ChadoFieldWidget {
     $field_name = $this->field['field_name'];
 
     // Get the field values.
-    $fkey_value = isset($form_state['values'][$field_name][$langcode][$delta]['value']) ? $form_state['values'][$field_name][$langcode][$delta]['value'] : '';
-    $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'] : '';
-    $uname = isset($form_state['values'][$field_name][$langcode][$delta]['uniquename']) ? $form_state['values'][$field_name][$langcode][$delta]['uniquename'] : '';
+    $fkey_value = $form_state['values'][$field_name]['und'][$delta]['value'];
+    $pub_id = $form_state['values'][$field_name]['und'][$delta]['chado-' . $table_name . '__pub_id'];
+    $title = $form_state['values'][$field_name]['und'][$delta]['pub_title'];
 
-    // If the user provided a uniquename then we want to set the foreign key
+    // If the user provided a pub_title then we want to set the foreign key
     // value to be the chado_record_id
-    if ($uname and !$pub_id) {
-      $pub = chado_generate_var('pub', array('uniquename' => $uname));
-      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__pub_id'] = $pub->pub_id;
+    if ($title) {
+      $matches = array();
+      if (preg_match('/^.*\[id:(\d+)]$/', $title, $matches)) {
+        $pub_id = $matches[1];
+        $pub = chado_generate_var('pub', array('pub_id' => $pub_id));
+        $form_state['values'][$field_name]['und'][$delta]['chado-' . $table_name . '__pub_id'] = $pub->pub_id;
+        $form_state['values'][$field_name]['und'][$delta]['value'] = $pub->pub_id;
+      }
     }
 
     // In the widgetFrom function we automatically add the foreign key
     // record.  But if the user did not provide a publication we want to take
     // it out so that the Chado field_storage infrastructure won't try to
     // write a record.
-    if (!$uname and !$pub_id) {
-      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__' . $fkey] = '';
-    }
-
-    // If the user removed the publication from the pub_uniquename field
-    // then we want to clear out the rest of the hidden values.
-    // Leave the primary key so the record can be deleted.
-    if (!$uname and $pub_id) {
-      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__' . $fkey] = '';
-      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__pub_id'] = '';
+    if (!$title) {
+      $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 . '__pub_id'] = '';
     }
   }
 
@@ -128,7 +134,7 @@ class schema__publication_widget extends ChadoFieldWidget {
     $layout = "
       <div class=\"pub-widget\">
         <div class=\"pub-widget-item\">" .
-          drupal_render($element['uniquename']) . "
+          drupal_render($element['pub_title']) . "
         </div>
       </div>
     ";

+ 12 - 52
tripal_chado/includes/TripalFields/sio__annotation/sio__annotation.inc

@@ -95,23 +95,17 @@ class sio__annotation extends ChadoField {
           $vocabulary_term => array(
             'sortable' => TRUE,
             'searchable' => TRUE,
-            'name' => 'vocabulary',
             'label' => 'Annotation Term Vocabulary',
-            'operations' => array('eq', 'ne', 'contains', 'starts'),
           ),
           $accession_term => array(
             'sortable' => TRUE,
             'searchable' => TRUE,
-            'name' => 'accession',
             'label' => 'Annotation Term Accession',
-            'operations' => array('eq', 'ne', 'contains', 'starts'),
           ),
-          $definition_term = array(
+          $definition_term => array(
             'sortable' => TRUE,
             'searchable' => TRUE,
-            'name' => 'description',
             'label' => 'Annotation Term Description',
-            'operations' => array('eq', 'ne', 'contains', 'starts'),
           ),
         ),
       ),
@@ -120,21 +114,17 @@ class sio__annotation extends ChadoField {
     if (array_key_exists('is_not', $schema['fields'])) {
       $negation_term = tripal_get_chado_semweb_term($field_table, 'is_not');
       $info[$field_term]['elements'][$negation_term] = array(
-        'sortable' => TRUE,
-        'searchable' => TRUE,
-        'name' => 'negates',
+        'sortable' => FALSE,
+        'searchable' => FALSE,
         'label' => 'Annotation Term Negates',
-        'operations' => array('eq', 'ne'),
       );
     }
     if (array_key_exists('rank', $schema['fields'])) {
       $rank_term = tripal_get_chado_semweb_term($field_table, 'rank');
       $info[$field_term]['elements'][$rank_term] = array(
-        'sortable' => TRUE,
-        'searchable' => TRUE,
-        'name' => 'rank',
+        'sortable' => FALSE,
+        'searchable' => FALSE,
         'label' => 'Annotation Term Rank',
-        'operations' => array('eq', 'ne', 'lte', 'gte'),
         'type' => 'numeric'
       );
     }
@@ -183,21 +173,6 @@ class sio__annotation extends ChadoField {
       $this->queryJoinOnce($query, 'cvterm', $alias . '_cvterm', $alias . ".cvterm_id = " . $alias . "_cvterm.cvterm_id");
       $query->condition($alias . '_cvterm.definition', $condition['value'], $operator);
     }
-
-    if (array_key_exists('is_not', $schema['fields'])) {
-      $negation_term = $field_term_id . ',' . tripal_get_chado_semweb_term($field_table, 'is_not');
-      if ($condition['column'] == $negation_term) {
-        $query->condition($alias . '.is_not', $condition['value'], $operator);
-      }
-    }
-    if (array_key_exists('rank', $schema['fields'])) {
-      $rank_term = $field_term_id . ',' . tripal_get_chado_semweb_term($field_table, 'rank');
-      if ($condition['column'] == $rank_term) {
-        $query->condition($alias . '.rank', $condition['value'], $operator);
-      }
-    }
-    if (array_key_exists('pub_id', $schema['fields'])) {
-    }
   }
 
   /**
@@ -224,35 +199,20 @@ class sio__annotation extends ChadoField {
     $this->queryJoinOnce($query, $field_table, $alias, "base.$fkey_rcolumn = $alias.$fkey_lcolumn");
 
     if ($order['column'] == $vocabulary_term) {
-      $this->queryJoinOnce($query, 'cvterm', $alias . '_cvterm', $alias . ".cvterm_id = " . $alias . "_cvterm.cvterm_id");
-      $this->queryJoinOnce($query, 'dbxref', $alias . '_dbxref', $alias . "_cvterm.dbxref_id = " . $alias . "_dbxref.dbxref_id");
-      $this->queryJoinOnce($query, 'db', $alias . '_db', $alias . "_db.db_id = " . $alias . "_dbxref.db_id");
-      $query->orderBy($alias . "_dbxref.name", $order['direction']);
+      $this->queryJoinOnce($query, 'cvterm', $alias . '_cvterm', $alias . ".cvterm_id = " . $alias . "_cvterm.cvterm_id", "LEFT OUTER");
+      $this->queryJoinOnce($query, 'dbxref', $alias . '_dbxref', $alias . "_cvterm.dbxref_id = " . $alias . "_dbxref.dbxref_id", "LEFT OUTER");
+      $this->queryJoinOnce($query, 'db', $alias . '_db', $alias . "_db.db_id = " . $alias . "_dbxref.db_id", "LEFT OUTER");
+      $query->orderBy($alias . "_db.name", $order['direction']);
     }
     if ($order['column'] == $accession_term) {
-      $this->queryJoinOnce($query, 'cvterm', $alias . '_cvterm', $alias . ".cvterm_id = " . $alias . "_cvterm.cvterm_id");
-      $this->queryJoinOnce($query, 'dbxref', $alias . '_dbxref', $alias . "_cvterm.dbxref_id = " . $alias . "_dbxref.dbxref_id");
+      $this->queryJoinOnce($query, 'cvterm', $alias . '_cvterm', $alias . ".cvterm_id = " . $alias . "_cvterm.cvterm_id", "LEFT OUTER");
+      $this->queryJoinOnce($query, 'dbxref', $alias . '_dbxref', $alias . "_cvterm.dbxref_id = " . $alias . "_dbxref.dbxref_id", "LEFT OUTER");
       $query->orderBy($alias . "_dbxref.accession", $order['direction']);
     }
     if ($order['column'] == $definition_term) {
       $this->queryJoinOnce($query, 'cvterm', $alias . '_cvterm', $alias . ".cvterm_id = " . $alias . "_cvterm.cvterm_id");
       $query->orderBy($alias . "_cvterm.definition", $order['direction']);
     }
-    if (array_key_exists('is_not', $schema['fields'])) {
-      $negation_term = $field_term_id . ',' . tripal_get_chado_semweb_term($field_table, 'is_not');
-      if ($order['column'] == $negation_term) {
-        $query->orderBy("$alias.is_not", $order['direction']);
-      }
-    }
-    if (array_key_exists('rank', $schema['fields'])) {
-      $rank_term = $field_term_id . ',' . tripal_get_chado_semweb_term($field_table, 'rank');
-      if ($order['column'] == $rank_term) {
-        $query->orderBy("$alias.rank", $order['direction']);
-      }
-    }
-    if (array_key_exists('pub_id', $schema['fields'])) {
-    }
-
   }
   /**
    *
@@ -320,7 +280,7 @@ class sio__annotation extends ChadoField {
         'value' => array(
           $vocabulary => $cvterm->dbxref_id->db_id->name,
           $accession => $cvterm->dbxref_id->accession,
-          $definition => $cvterm->name
+          $definition => $cvterm->definition
         ),
         'chado-' . $field_table . '__' . $pkey => $linker->$pkey,
         'chado-' . $field_table . '__' . $fkey_lcolumn => $linker->$fkey_lcolumn,

+ 0 - 30
tripal_chado/includes/TripalFields/sio__references/sio__references.inc

@@ -66,36 +66,6 @@ class sio__references extends ChadoField {
         'operations' => array(),
         'sortable' => FALSE,
         'searchable' => FALSE,
-        'elements' => array(
-          'rdfs:type' => array(
-            'searchable' => TRUE,
-            'name' => 'type',
-            'label' => 'Reference Type',
-            'help' => 'The type of item referred to by the publication.',
-            'operations' => array('eq', 'ne', 'contains', 'starts'),
-            'sortable' => TRUE,
-          ),
-          'schema:name' => array(
-            'searchable' => TRUE,
-            'name' => 'name',
-            'label' => 'Reference Name',
-            'help' => 'The name of the item referred to by the publication.',
-            'operations' => array('eq', 'ne', 'contains', 'starts'),
-            'sortable' => TRUE,
-          ),
-          'data:0842'=> array(
-            'searchable' => TRUE,
-            'name' => 'identifier',
-            'label' => 'Reference Identifier',
-            'help' => 'The unique identifier of the item referred to by the publication.',
-            'operations' => array('eq', 'ne', 'contains', 'starts'),
-            'sortable' => TRUE,
-          ),
-          'entity'=> array(
-            'searchable' => FALSE,
-            'sortable' => FALSE,
-          ),
-        ),
       ),
     );
   }

+ 29 - 2
tripal_chado/includes/TripalFields/sio__vocabulary/sio__vocabulary_widget.inc

@@ -22,7 +22,34 @@ class sio__vocabulary_widget extends ChadoFieldWidget {
     $field_table = $this->instance['settings']['chado_table'];
     $field_column = $this->instance['settings']['chado_column'];
 
-    $cv_id = 0;
+    // If the items array is empty then we are creating a new entity.
+    // Since this is set when the entity type is created, we don't want to allow
+    // content managers to change it. Thus we need to look up the value for the
+    // entity type and use it here.
+    if (empty($items)) {
+      // Use the bundle to get the cv_id choosen for this cvterm-based entity.
+      // ASSUMPTION: the cv_id is saved as the "type_value" of the bundle.
+      $bundle = tripal_load_bundle_entity(array('name' => $widget['#bundle']));
+      $cv = tripal_get_cv(array('cv_id' => $bundle->type_value));
+
+      // Now populate the items array with defaults based on the cv.
+      if ($cv) {
+        $items[$delta] = array(
+          'value' => $cv->name,
+          'chado-' . $field_table . '__cv_id' => $cv->cv_id,
+        );
+      }
+      else {
+        tripal_report_error(
+          $field_name,
+          TRIPAL_ERROR,
+          'Unable to determine default vocabulary for :name Tripal Content Type',
+          array(':name' => $bundle->label)
+        );
+        drupal_set_message(t('Unable to determine default vocabulary for :name Tripal Content Type',
+          array(':name' => $bundle->label)), 'error');
+      }
+    }
 
     $widget['value'] = array(
       '#type' => 'value',
@@ -30,7 +57,7 @@ class sio__vocabulary_widget extends ChadoFieldWidget {
     );
     $widget['chado-' . $field_table . '__cv_id'] = array(
       '#type' => 'value',
-      '#value' => $items[$delta]['chado-' . $field_table . '__cv_id'],
+      '#value' => array_key_exists($delta, $items) ? $items[$delta]['chado-' . $field_table . '__cv_id'] : '',
     );
     $widget['vocabulary_name'] = array(
       '#type' => 'item',

+ 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,
           ),
         )

+ 5 - 0
tripal_chado/includes/TripalFields/uo__unit/uo__unit.inc

@@ -56,6 +56,11 @@ class uo__unit extends ChadoField {
 
     if ($record) {
       $entity->{$field_name}['und'][0]['value'] = $record->unittype_id->name;
+      $entity->{$field_name}['und'][0]['chado-' . $field_table . '__unittype_id'] = $record->unittype_id->cvterm_id;
+      $entity->{$field_name}['und'][0]['chado-cvterm__name'] = $record->unittype_id->name;
+      $entity->{$field_name}['und'][0]['chado-cvterm__definition'] = $record->unittype_id->definition;
+      $entity->{$field_name}['und'][0]['chado-cvterm__cv_id'] = $record->unittype_id->cv_id->cv_id;
+      $entity->{$field_name}['und'][0]['chado-cv__name'] = $record->unittype_id->cv_id->name;
     }
   }
 }

+ 42 - 1
tripal_chado/includes/TripalFields/uo__unit/uo__unit_widget.inc

@@ -16,6 +16,47 @@ class uo__unit_widget extends ChadoFieldWidget {
 
     parent::form($widget, $form, $form_state, $langcode, $items, $delta, $element);
 
-    // TODO: add a form for changing the unit types.
+    $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'];
+
+    $unittype_id = 0;
+    if (count($items) > 0 and array_key_exists('chado-' . $field_table . '__unittype_id', $items[0])) {
+      $unittype_id = $items[0]['chado-' . $field_table . '__unittype_id'];
+    }
+
+    $widget['value'] = array(
+      '#type' => 'value',
+      '#value' => array_key_exists($delta, $items) ? $items[$delta]['value'] : '',
+    );
+    $cv = tripal_get_cv(array('name' => 'featuremap_units'));
+    $options = tripal_get_cvterm_select_options($cv->cv_id);
+    unset($options[0]);
+    $widget['chado-' . $field_table . '__unittype_id'] = array(
+      '#type' => 'select',
+      '#title' => $element['#title'],
+      '#description' => $element['#description'],
+      '#options' => $options,
+      '#default_value' => $unittype_id,
+      '#empty_option' => '- Select a Unit -',
+      '#required' => $element['#required'],
+      '#weight' => isset($element['#weight']) ? $element['#weight'] : 0,
+      '#delta' => $delta,
+    );
+  }
+
+  /**
+   * @see TripalFieldWidget::validate()
+   */
+  public function validate($element, $form, &$form_state, $langcode, $delta) {
+
+    $field_name = $this->field['field_name'];
+    $field_table = $this->instance['settings']['chado_table'];
+
+    // Make sure the value is set to the organism_id
+    $unittype_id = $form_state['values'][$field_name]['und'][0]['chado-' . $field_table . '__unittype_id'];
+    $form_state['values'][$field_name]['und'][0]['value'] = $unittype_id;
   }
 }

+ 14 - 12
tripal_chado/includes/setup/tripal_chado.setup.inc

@@ -136,13 +136,15 @@ function tripal_chado_load_ontologies() {
 /**
  * Prepares Chado for use by Tripal.
  */
-function tripal_chado_prepare_chado($job) {
+function tripal_chado_prepare_chado($job = NULL) {
 
   // Retrieve the job arguement in order to report progress.
   if (is_int($job)) {
     $job = new TripalJob();
     $job->load($job_id);
   }
+  $report_progress = TRUE;
+  if (!is_object($job)) { $report_progress = FALSE; }
 
   try {
 
@@ -176,19 +178,19 @@ function tripal_chado_prepare_chado($job) {
       tripal_chado_fix_v1_3_custom_tables();
     }
 
-    $job->setProgress(5);
+    if ($report_progress) { $job->setProgress(5); }
 
     // Import commonly used ontologies if needed.
     drush_print("Loading Ontologies...");
     tripal_chado_load_ontologies();
 
-    $job->setProgress(50);
+    if ($report_progress) { $job->setProgress(50); }
 
     // Populate the semantic web associations for Chado tables/fields.
     drush_print("Making semantic connections for Chado tables/fields...");
     tripal_chado_populate_chado_semweb_table();
 
-    $job->setProgress(60);
+    if ($report_progress) { $job->setProgress(60); }
 
     // Initialize the population of the chado_cvterm_mapping table.  This will
     // map existing data types already in Chado so that when users want to
@@ -196,7 +198,7 @@ function tripal_chado_prepare_chado($job) {
     drush_print("Map Chado Controlled vocabularies to Tripal Terms...");
     tripal_chado_map_cvterms();
 
-    $job->setProgress(70);
+    if ($report_progress) { $job->setProgress(70); }
 
     drush_print("Creating common Tripal Content Types...");
 
@@ -217,7 +219,7 @@ function tripal_chado_prepare_chado($job) {
         throw new Exception($error['!message']);
       }
     }
-    $job->setProgress(74);
+    if ($report_progress) { $job->setProgress(74); }
 
     // Create the 'Analysis' entity type. This uses the local:analysis term.
     $error = '';
@@ -236,7 +238,7 @@ function tripal_chado_prepare_chado($job) {
         throw new Exception($error['!message']);
       }
     }
-    $job->setProgress(78);
+    if ($report_progress) { $job->setProgress(78); }
 
     // Create the 'Project' entity type. This uses the local:project term.
     $error = '';
@@ -255,7 +257,7 @@ function tripal_chado_prepare_chado($job) {
         throw new Exception($error['!message']);
       }
     }
-    $job->setProgress(82);
+    if ($report_progress) { $job->setProgress(82); }
 
     // Create the 'Map' entity type. This uses the local:project term.
     $error = '';
@@ -281,7 +283,7 @@ function tripal_chado_prepare_chado($job) {
     );
     $cvterm = tripal_get_cvterm($identifier);
     tripal_chado_add_cvterm_mapping($cvterm->cvterm_id, 'featuremap', NULL);
-    $job->setProgress(86);
+    if ($report_progress) { $job->setProgress(86); }
 
     // Import a publication so we get all of the properties before
     // creating the content type.
@@ -323,7 +325,7 @@ function tripal_chado_prepare_chado($job) {
     );
     $result = chado_select_record('pub_dbxref', array('pub_id'), $values);
     chado_delete_record('pub', array('pub_id' => $result[0]->pub_id));
-    $job->setProgress(90);
+    if ($report_progress) { $job->setProgress(90); }
 
     // Create the 'Gene' entity type.
     $error = '';
@@ -343,7 +345,7 @@ function tripal_chado_prepare_chado($job) {
         throw new Exception($error['!message']);
       }
     }
-    $job->setProgress(94);
+    if ($report_progress) { $job->setProgress(94); }
 
     // Create the 'mRNA' entity type.
     $error = '';
@@ -363,7 +365,7 @@ function tripal_chado_prepare_chado($job) {
         throw new Exception($error['!message']);
       }
     }
-    $job->setProgress(98);
+    if ($report_progress) { $job->setProgress(98); }
 
     // Add the supported loaders
     variable_set('tripal_pub_supported_dbs', array('PMID', 'AGL'));

+ 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();
 

+ 241 - 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,13 @@ 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');
+
+         // Skip the Publiation Type property for pubs as this is
+         // already handled by the pub.type_id field.
+         if ($term->name == 'Publication Type' and $term->cv_id->name == 'tripal_pub') {
+           continue;
+         }
 
          // The tripal_analysis_KEGG, tripal_analysis_blast, and
          // tripal_analysis_interpro modules store results in the analysisprop
@@ -1771,6 +1816,21 @@ function tripal_chado_bundle_instances_info_linker(&$info, $entity_type, $bundle
              ),
            ),
          );
+
+         // Make some customizations to some fields
+         if ($term->name == 'Citation' and $term->cv_id->name == 'tripal_pub') {
+           $info[$field_name]['required'] = TRUE;
+           $info[$field_name]['description'] = t('All publications must have a unique citation.
+            Please enter the full citation for this publication.  For PubMed style citations list
+            the last name of the author followed by initials. Each author should be separated by a comma. Next comes
+            the title, followed by the series title (e.g. journal name), publication date (4 digit year, 3 character Month, day), volume, issue and page numbers. You may also use HTML to provide a link in the citation.
+            Below is an example: <pre>Medeiros PM, Ladio AH, Santos AM, Albuquerque UP. <a href="http://www.ncbi.nlm.nih.gov/pubmed/23462414" target="_blank">Does the selection of medicinal plants by Brazilian local populations
+              suffer taxonomic influence?</a> J Ethnopharmacol. 2013 Apr 19; 146(3):842-52.</pre>');
+           $info[$field_name]['settings']['rows'] = 3;
+         }
+         if ($term->name == 'Abstract' and $term->cv_id->name == 'tripal_pub') {
+           $info[$field_name]['settings']['rows'] = 5;
+         }
        }
      }
    }

+ 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

+ 42 - 0
tripal_chado/tripal_chado.install

@@ -1159,4 +1159,46 @@ 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);
+  }
+}
+
+/**
+ * Run the cvtermpath for the Tripal Pub and Contact ontologies.
+ */
+function tripal_chado_update_7313() {
+  try {
+    $cv = tripal_get_cv(array('name' => 'tripal_pub'));
+    tripal_update_cvtermpath($cv->cv_id);
+    $cv = tripal_get_cv(array('name' => 'tripal_contact'));
+    tripal_update_cvtermpath($cv->cv_id);
+  }
+  catch (\PDOException $e) {
+    $error = $e->getMessage();
+    throw new DrupalUpdateException('Could not perform update: '. $error);
+  }
 }

+ 0 - 1
tripal_ds/tripal_ds.install

@@ -79,7 +79,6 @@ function tripal_ds_disable(){
   $output .= '</ul>';
   if(!empty($entities_with_tripal_panes)){
     drupal_set_message($output, 'warning');
-
   }
 }
 

+ 13 - 5
tripal_ws/includes/TripalWebService/TripalEntityService_v0_1.inc

@@ -6,13 +6,15 @@ class TripalEntityService_v0_1 extends TripalWebService {
    * The human-readable label for this web service.
    */
   public static $label = 'Content Types';
+
   /**
    * A bit of text to describe what this service provides.
    */
-  public static $description = 'Provides acesss to the biological and ' .
-    'ancilliary data available on this site. Each content type represents ' .
-    'biological data that is defined in a controlled vocabulary (e.g. ' .
-    'Sequence Ontology term: gene (SO:0000704)).';
+  public static $description = 'Provides acesss to the biological and
+    ancilliary data available on this site. Each content type represents
+    biological data that is defined in a controlled vocabulary (e.g.
+    Sequence Ontology term: gene (SO:0000704)).';
+
   /**
    * A machine-readable type for this service. This name must be unique
    * among all Tripal web services and is used to form the URL to access
@@ -809,8 +811,14 @@ class TripalEntityService_v0_1 extends TripalWebService {
 
     $this->resource->initPager($num_records, $limit, $page);
 
+    // Check to make sure there are results.
+    $entity_ids = array();
+    if (isset($results['TripalEntity']) AND is_array($results['TripalEntity'])) {
+      $entity_ids = $results['TripalEntity'];
+    }
+
     // Iterate through the entities and add them to the output list.
-    foreach ($results['TripalEntity'] as $entity_id => $stub) {
+    foreach ($entity_ids as $entity_id => $stub) {
       // We don't need all of the attached fields for an entity so, we'll
       // not use the entity_load() function.  Instead just pull it from the
       // database table.