Forráskód Böngészése

Fixed issues with the additionalType field and addressing issue #234

Stephen Ficklin 7 éve
szülő
commit
a71dfda64d

+ 202 - 0
tripal/api/tripal.terms.api.inc

@@ -295,3 +295,205 @@ function tripal_get_vocabulary_details($vocabulary) {
     }
   }
 }
+
+
+/**
+ * Provides a term lookup form.
+ *
+ * It may be necessary at times for a form to provide to the user the ability
+ * to lookup and use a controlled vocabulary term.  However, a simple text box
+ * or auto-lookup is not sufficient because a term name may be identical in
+ * multiple vocabularies and the user would need to select the proper term.
+ *
+ * This function will add the form elements necessary to provide a lookup form.
+ * The form elements should work with a flat fortm (no #tree set for the form)
+ * or with a form in a TripalField.
+ *
+ * Use the tripal_get_term_lookup_form_result() function to retreive the
+ * result in a form submit or validate.
+ *
+ * @param $form
+ *   The form (or $widget form).
+ * @param $form_state
+ *   The form state.
+ * @param $title
+ *   The title to give to the field set.
+ * @param $description
+ *   A description for the lookup field element.
+ * @param $is_required
+ *   Indicates if this form element is required.
+ * @param $field_name
+ *   The name of the field, if this form is being added to a field widget.
+ * @param  $delta
+ *   The delta value for the field if this form is being added to a field
+ *   widget.
+ */
+function tripal_get_term_lookup_form(&$form, &$form_state, $default_name = '',
+    $title = 'Vocabulary Term', $description = '', $is_required,
+    $field_name = '', $delta = 0 ) {
+
+  $term_name = $default_name;
+  if (array_key_exists('values', $form_state)) {
+    $term_name = $form_state['values']['term_name'];
+  }
+  if ($field_name and array_key_exists('input', $form_state) and array_key_exists($field_name, $form_state['input'])) {
+    $term_name = $form_state['input'][$field_name]['und'][$delta]['term_match']['term_name'];
+  }
+
+  if (!$description) {
+    $description = t('Enter the name of the term that specifies the type. ' .
+      'The type must be the name of a term in a controlled vocabulary and ' .
+      'the controlled vocabulary should already be loaded into this site.');
+  }
+
+  $form_state['storage']['term_match_field'] = $field_name;
+  $form_state['storage']['term_match_delta'] = $delta;
+
+  $form['term_match'] = array(
+    '#type' => 'fieldset',
+    '#collapsible' => FALSE,
+    '#collapsed' => FALSE,
+    '#title' => t($title),
+    '#prefix' => '<div id = "tripal-vocab-select-form">',
+    '#suffix' => '</div>',
+  );
+  $form['term_match']['term_name'] = array(
+    '#title'  => t('Type'),
+    '#type' => 'textfield',
+    '#description' => $description,
+    '#required' => $is_required,
+    '#default_value' => $term_name,
+    '#autocomplete_path' => "admin/tripal/storage/chado/auto_name/cvterm/",
+  );
+  $form['term_match']['select_button'] = array(
+    '#type' => 'button',
+    '#value' => t('Lookup Term'),
+    '#name' => 'select_cvterm',
+    '#validate' => array(),
+    '#limit_validation_errors' => array(),
+    '#ajax' => array(
+      'callback' => "tripal_get_term_lookup_form_ajax_callback",
+      'wrapper' => "tripal-vocab-select-form",
+      'effect' => 'fade',
+      'method' => 'replace'
+    ),
+  );
+
+  // If the term has been provided by the user then we want to search for
+  // matching terms in the database and let them select among any matches.
+  if ($term_name) {
+    $submit_disabled = TRUE;
+    $form['term_match']['terms_list'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Matching Terms'),
+      '#description' => t('Please select the term the best matches the
+          content type you want to create. If the same term exists in
+          multiple vocabularies you will see more than one option below.')
+    );
+    $match = array(
+      'name' => $term_name,
+    );
+    // TODO: this should not call the chado functions because we're in the
+    // tripal module.
+    $terms = chado_generate_var('cvterm', $match, array('return_array' => TRUE));
+    $terms = chado_expand_var($terms, 'field', 'cvterm.definition');
+    $num_terms = 0;
+    $selected_term = '';
+
+    // Let the user select from any matching terms. Sometimes there may be
+    // more than one that match.
+    foreach ($terms as $term) {
+      // Save the user a click by setting the default value as 1 if there's
+      // only one matching term.
+      $default = FALSE;
+      $attrs = array();
+      if ($num_terms == 0 and count($terms) == 1) {
+        $default = TRUE;
+        $attrs = array('checked' => 'checked');
+      }
+      $term_element_name = 'term-' . $term->cvterm_id;
+      $form['term_match']['terms_list'][$term_element_name] = array(
+        '#type' => 'checkbox',
+        '#title' =>  $term->name,
+        '#default_value' => $default,
+        '#attributes' => $attrs,
+        '#description' => '<b>Vocabulary:</b> ' . $term->cv_id->name . ' (' . $term->dbxref_id->db_id->name . ') ' . $term->cv_id->definition .
+        '<br><b>Term: </b> ' . $term->dbxref_id->db_id->name . ':' . $term->dbxref_id->accession . '.  ' .
+        '<br><b>Definition:</b>  ' . $term->definition,
+        '#ajax' => array(
+          'callback' => "tripal_get_term_lookup_form_ajax_callback",
+          'wrapper' => "tripal-vocab-select-form",
+          'effect' => 'fade',
+          'method' => 'replace'
+        ),
+      );
+
+      if (array_key_exists('values', $form_state) and array_key_exists($term_element_name, $form_state['values']) and
+          $form_state['values'][$term_element_name] == 1) {
+        $selected_term = $term;
+      }
+      $num_terms++;
+    }
+    if ($num_terms == 0) {
+      $form['term_match']['terms_list']['none'] = array(
+        '#type' => 'item',
+        '#markup' => '<i>' . t('There is no term that matches the entered text.') . '</i>'
+      );
+    }
+  }
+}
+
+/**
+ * Returns the terms selected from the tripal_get_term_lookup_form.
+ *
+ * @param $form
+ *   The form (or $widget form).
+ * @param $form_state
+ *   The form state.
+ * @param $field_name
+ *   The name of the field, if this form is being added to a field widget.
+ * @param  $delta
+ *   The delta value for the field if this form is being added to a field
+ *   widget.
+ *
+ * @return
+ *   An array of term objects for each of the user selected terms.
+ */
+function tripal_get_term_lookup_form_result($form, $form_state, $field_name = '', $delta = 0) {
+  $values = array();
+  $selected = array();
+  if ($field_name) {
+    if (array_key_exists('term_match', $form_state['values'][$field_name]['und'][$delta])) {
+      $values = $form_state['values'][$field_name]['und'][$delta]['term_match']['terms_list'];
+    }
+  }
+  else {
+    $values = $form_state['values'];
+  }
+
+  foreach ($values as $key => $value) {
+    $matches = array();
+    if (preg_match("/^term-(\d+)$/", $key, $matches) and $values['term-' . $matches[1]]) {
+      $cvterm_id = $matches[1];
+      $selected[] = chado_generate_var('cvterm', array('cvterm_id' => $cvterm_id));
+    }
+  }
+  return $selected;
+}
+
+/**
+ * Implements an AJAX callback for the tripal_chado_vocab_select_term_form.
+ */
+function tripal_get_term_lookup_form_ajax_callback($form, $form_state) {
+  $field_name = $form_state['storage']['term_match_field'];
+  $delta = $form_state['storage']['term_match_delta'];
+
+  // If this form is in a field then we need to dig a bit deeper to return
+  // the form elements.
+  if ($field_name) {
+    return $form[$field_name]['und'][$delta]['term_match'];
+  }
+  else {
+    return $form['term_match'];
+  }
+}

+ 1 - 1
tripal_chado/api/modules/tripal_chado.analysis.api.inc

@@ -147,7 +147,7 @@ function tripal_get_analysis_select_options($syncd_only = TRUE) {
         INNER JOIN {analysis} A ON A.analysis_id = CO.analysis_id
       ORDER BY A.name
     ";
-    $orgs = chado_query($sql);
+    $analyses = chado_query($sql);
 
     // iterate through the analyses and build an array of those that are synced
     foreach ($analyses as $analysis) {

+ 37 - 9
tripal_chado/api/modules/tripal_chado.cv.api.inc

@@ -419,7 +419,7 @@ function tripal_update_cvtermpath($cv_id, $job_id = NULL){
  *   The controlled vocabulary ID from the cv table of Chado (i.e. cv.cv_id).
  */
 function tripal_update_cvtermpath_root_loop($rootid, $cvid, &$roots) {
-  
+
   // Get's the cvterm record for this "root".
   $ttype = db_select('cvterm', 'cv')
           ->fields('cv', array('cvterm_id'));
@@ -485,13 +485,13 @@ function tripal_update_cvtermpath_root_loop($rootid, $cvid, &$roots) {
  * @param $possible_loop
  *    A boolean flag.
  * @param $matched_row
- *    An array of rows that are currently in the cvtermpath table that match the 
+ *    An array of rows that are currently in the cvtermpath table that match the
  *    build_id of the current term trying to be written to the table
  * @param $possible_start_of_ loop
- *    The array of the possible loop item between the current child and the origin. 
+ *    The array of the possible loop item between the current child and the origin.
  *    Each element in the array is an associative array with the keys:
  *     - cvid : $cv_id
- *     - subject_id: 
+ *     - subject_id:
  *     - child_id : $child_id,
  *     - type_id : $type_id,
  *     - depth : $depth,
@@ -529,7 +529,7 @@ function tripal_update_cvtermpath_loop(
         array(':cvtermpath_id' => $cvtermpath_id)
       );
       $next_row = $next_row->fetchObject();
-      
+
       // If the next row matches the values passed we can't rule out a loop.
       if (($next_row->type_id === $type_id) &&
           ($next_row->subject_id === $child_id) &&
@@ -641,13 +641,13 @@ function tripal_update_cvtermpath_loop(
  * @param $possible_loop
  *    A boolean flag.
  * @param $matched_row
- *    An array of rows that are currently in the cvtermpath table that match the 
+ *    An array of rows that are currently in the cvtermpath table that match the
  *    build_id of the current term trying to be written to the table
  * @param $possible_start_of_ loop
- *    The array of the possible loop item between the current child and the origin. 
+ *    The array of the possible loop item between the current child and the origin.
  *    Each element in the array is an associative array with the keys:
  *     - cvid : $cv_id
- *     - subject_id: 
+ *     - subject_id:
  *     - child_id : $child_id,
  *     - type_id : $type_id,
  *     - depth : $depth,
@@ -730,7 +730,7 @@ function tripal_update_cvtermpath_loop_increment(
           }
         }
       }
-    
+
       $query = db_insert('cvtermpath')
         ->fields([
           'object_id' => $origin,
@@ -1373,7 +1373,35 @@ function tripal_get_obo($values) {
   }
   return $query->execute()->fetchObject();
 }
+/**
+ * This function is intended to be used in autocomplete forms.
+ *
+ * This function searches for a matching controlled vobulary name.
+ *
+ * @param $string
+ * The string to search for
+ *
+ * @return
+ * A json array of terms that begin with the provided string
+ *
+ * @ingroup tripal_chado_api
+ */
+function tripal_autocomplete_cv($string = '') {
+  $sql = "
+    SELECT CV.cv_id, CV.name
+    FROM {cv} CV
+    WHERE lower(CV.name) like lower(:name)
+    ORDER by CV.name
+    LIMIT 25 OFFSET 0
+  ";
+  $results = chado_query($sql, array(':name' => $string . '%'));
+  $items = array();
+  foreach ($results as $cv) {
+    $items[$cv->name] = $cv->name;
+  }
 
+  drupal_json_output($items);
+}
 /**
  * This function is intended to be used in autocomplete forms
  * for searching for CV terms that begin with the provided string

+ 80 - 2
tripal_chado/includes/TripalFields/schema__additional_type/schema__additional_type.inc

@@ -97,9 +97,87 @@ class schema__additional_type extends ChadoField {
 
     // Set some defaults for the empty record.
     $entity->{$field_name}['und'][0] = array(
-      'value' => $record->type_id->name,
-      'chado-' . $field_table . '__type_id' => $record->type_id->cvterm_id,
+      'value' => '',
+      'chado-' . $field_table . '__type_id' => '',
     );
+
+    if ($record->type_id) {
+      $entity->{$field_name}['und'][0] = array(
+        'value' => $record->type_id->name,
+        'chado-' . $field_table . '__type_id' => $record->type_id->cvterm_id,
+      );
+    }
+  }
+
+  /**
+   * @see ChadoField::instanceSettingsForm()
+   */
+  public function instanceSettingsForm(){
+    $element = parent::instanceSettingsForm();
+    $settings = $this->instance['settings'];
+
+    $element['vocabulary']  = array(
+      '#title'  => t('Enforce Vocabulary'),
+      '#type' => 'textfield',
+      '#description' => t('Optional. Enter the name of the vocabulary that must be used when the user selects a term for the additional type. If no value is provided then the user can select from any term available on the site.') ,
+      '#default_value' => $settings['vocabulary'],
+      '#autocomplete_path' => "admin/tripal/storage/chado/auto_name/cv",
+    );
+
+    $element['parent_term']  = array(
+      '#title'  => t('Enforce Parent Term'),
+      '#type' => 'textfield',
+      '#description' => t('Optional. If a vocabulary is heirarchical and if the user should be restricted to a set of terms below a given parent term, then enter the parent term here. The term should be in the form {db}:{accession} where {db} is the short name for the database (e.g. GO, SO, TPUB, TContact) and {accession} is the unique identifier for that term in the vocabulary (e.g. TContact:0000001).') ,
+      '#default_value' => $settings['parent_term'],
+    );
+
+    return $element;
   }
 
+  /**
+   * @see TripalField::settingsFormValidate()
+   */
+  public function settingsFormValidate($form, &$form_state) {
+    $element = parent::settingsFormValidate($form, $form_state);
+
+    $values = $form_state['values']['instance']['settings'];
+
+    // Make sure te vocabulary and parent term exist
+    $vocabulary = $values['vocabulary'];
+    $parent_term = $values['parent_term'];
+
+    $good_vocab = FALSE;
+    if ($vocabulary) {
+      $sql = "SELECT cv_id FROM {cv} WHERE name = :name";
+      $results = chado_query($sql, array(':name' => $vocabulary));
+      $cv_id = $results->fetchField();
+      if (!$cv_id) {
+        form_set_error('instance][settings][vocabulary', 'Invalid vocabulary');
+      }
+      else {
+        $good_vocab =  TRUE;
+      }
+    }
+
+    if ($parent_term and $good_vocab) {
+      $matches = array();
+      if (preg_match('/^(.+):(.+)$/', $parent_term, $matches)) {
+        $db = $matches[1];
+        $accession = $matches[2];
+        $values = array(
+          'db_id' => array(
+            'name' => $db,
+          ),
+          'accession' => $accession,
+        );
+        $records = chado_select_record('dbxref', array('dbxref_id'), $values);
+        if (count($records) == 0) {
+          form_set_error('instance][settings][parent_term', 'The specified parent term does not exist on this site. Please check the entry.');
+        }
+      }
+      else {
+        form_set_error('instance][settings][parent_term', 'Please provide a parent term in the correct format.');
+      }
+    }
+  }
 }

+ 42 - 14
tripal_chado/includes/TripalFields/schema__additional_type/schema__additional_type_widget.inc

@@ -22,7 +22,6 @@ class schema__additional_type_widget extends ChadoFieldWidget {
     $vocabulary = $this->instance['settings']['vocabulary'];
     $parent_term = $this->instance['settings']['parent_term'];
 
-    $record_id = $element['#entity']->chado_record_id;
     $value = '';
     $type_id = '';
 
@@ -40,9 +39,6 @@ class schema__additional_type_widget extends ChadoFieldWidget {
       '#value' => $value,
     );
 
-    If ($field_table == 'pub' && empty($vocabulary)){
-      $vocabulary = 'tripal_pub';
-    };
     // If a parent_term is provided then use that to get the options
     $options = array();
     $options[] = 'Select a type';
@@ -55,10 +51,13 @@ class schema__additional_type_widget extends ChadoFieldWidget {
           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 {cvterm} CVTT ON CVTP.type_id = CVTT.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
+            (CVTT.name = 'is a' OR CVTT.name = 'is_a') AND
+            CVTS.name != CVTO.name AND
             NOT CVTS.is_obsolete = 1
           ORDER BY CVTS.name ASC
        ";
@@ -72,15 +71,31 @@ class schema__additional_type_widget extends ChadoFieldWidget {
       $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,
-    );
+    // If no vocabulary or parent term are provided then just give a generic
+    // term finder.
+    else {
+      $cvterm = NULL;
+      $default_name = '';
+      if ($type_id) {
+        $cvterm = chado_generate_var('cvterm', array('cvterm_id' => $type_id));
+        $default_name = $cvterm->name;
+      }
+      tripal_get_term_lookup_form($widget, $form_state, $default_name,
+          $element['#title'], $element['#description'], $element['#required'],
+          $field_name, $delta);
+    }
+    if ($vocabulary) {
+      $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,
+        '#required' => $element['#required'],
+        '#delta' => $delta,
+      );
+    }
   }
 
   /**
@@ -97,7 +112,20 @@ class schema__additional_type_widget extends ChadoFieldWidget {
     $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'];
+    // Get the vocabulary term.
+    $type_id = '';
+    if ($vocabulary) {
+      $type_id = $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__type_id'];
+    }
+    else {
+      $selected = tripal_get_term_lookup_form_result($form, $form_state, $field_name, $delta);
+      if (count($selected) == 1) {
+        $type_id = $selected[0]->cvterm_id;
+      }
+      if (count($selected) > 1) {
+        form_set_error($field_name . '[' . $langcode . '][' . $delta . '][term_match][term_name', 'Please select only one vocabulary term.');
+      }
+    }
 
     if (!$type_id) {
       $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__type_id'] = '__NULL__';

+ 56 - 20
tripal_chado/includes/tripal_chado.fields.inc

@@ -115,6 +115,11 @@ function tripal_chado_bundle_fields_info_base(&$info, $details, $entity_type, $b
       continue;
     }
 
+    // Skip the type ID as it will be handled by a custom field.
+    if ($column_name == 'type_id') {
+      continue;
+    }
+
     // Set some defaults for the field.
     $base_info = array(
       'field_name' => $field_name,
@@ -191,7 +196,6 @@ function tripal_chado_bundle_fields_info_base(&$info, $details, $entity_type, $b
       $base_info['type'] = 'text';
       $base_info['settings']['text_processing'] = 0;
     }
-
     $info[$field_name] = $base_info;
   }
 }
@@ -209,8 +213,8 @@ function tripal_chado_bundle_fields_info_custom(&$info, $details, $entity_type,
 
   $schema = chado_get_schema($table_name);
 
-  // An additional type for the publication
-  if ($table_name == 'pub') {
+  // Handle type_id fields that are not the type_column.
+  if (array_key_exists('type_id', $schema['fields']) and 'type_id' != $type_column) {
     $field_name = 'schema__additional_type';
     $field_type = 'schema__additional_type';
     $info[$field_name] = array(
@@ -452,7 +456,7 @@ function tripal_chado_bundle_fields_info_custom(&$info, $details, $entity_type,
 
 /**
  *
- * @param unknown $details
+ * @param $details
  */
 function tripal_chado_bundle_fields_info_linker(&$info, $details, $entity_type, $bundle) {
 
@@ -776,14 +780,19 @@ function tripal_chado_bundle_instances_info_base(&$info, $entity_type, $bundle,
       continue;
     }
 
-    // Don't create base fields for the primary key and the type_id field.
-    if ($column_name == $pkey or $column_name == $type_column) {
+    // Skip the cvterm.is_relationshptype.
+    if ($table_name == 'cvterm' and $column_name == 'is_relationshiptype') {
       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') {
+    // The biosourceprovider_id and taxon_id are handled by custom fields.
+    if ($table_name == 'biomaterial' and (
+        $column_name == 'biosourceprovider_id' or $column_name == 'taxon_id')) {
+      continue;
+    }
+
+    // Don't create base fields for the primary key and the type_id field.
+    if ($column_name == $pkey or $column_name == $type_column) {
       continue;
     }
 
@@ -793,12 +802,6 @@ function tripal_chado_bundle_instances_info_base(&$info, $entity_type, $bundle,
       // don't create another one here.
       continue;
     }
-
-    if ($table_name == 'biomaterial' and (
-        $column_name == 'biosourceprovider_id' or $column_name == 'taxon_id')) {
-      continue;
-    }
-
     $field_name = strtolower($cvterm->dbxref_id->db_id->name . '__' . preg_replace('/[^\w]/', '_', $cvterm->name));
     $field_name = substr($field_name, 0, 32);
 
@@ -813,6 +816,11 @@ function tripal_chado_bundle_instances_info_base(&$info, $entity_type, $bundle,
       continue;
     }
 
+    // Skip the type ID as it will be handled by a custom field.
+    if ($column_name == 'type_id') {
+      continue;
+    }
+
     $base_info =  array(
       'field_name' => $field_name,
       'entity_type' => 'TripalEntity',
@@ -1017,6 +1025,14 @@ function tripal_chado_bundle_instances_info_base(&$info, $entity_type, $bundle,
       $base_info['label'] = 'Short Description';
     }
 
+    //
+    // CONTACT TABLE
+    //
+    if ($table_name == 'contact' and $column_name == 'description') {
+      $base_info['label'] = 'Short Description';
+    }
+
+
     $info[$field_name] = $base_info;
   }
 }
@@ -1040,27 +1056,47 @@ function tripal_chado_bundle_instances_info_custom(&$info, $entity_type, $bundle
   $schema = chado_get_schema($table_name);
 
   // An additional type for publications
-  if ($table_name == 'pub') {
+  if (array_key_exists('type_id', $schema['fields']) and 'type_id' != $type_column) {
     $field_name = 'schema__additional_type';
     $is_required = FALSE;
     if (array_key_exists('not null', $schema['fields']['type_id']) and
         $schema['fields']['type_id']['not null']) {
       $is_required = TRUE;
     }
+    $label = ucwords(preg_replace('/_/', ' ', $table_name)) . ' Type';
+    $default_vocab = '';
+    $parent_term = '';
+    switch($table_name) {
+      case 'pub':
+        $default_vocab = 'tripal_pub';
+        $label = 'Publication Type';
+        $parent_term = 'TPUB:0000015';
+        $description = 'Select the type.';
+        break;
+      case 'contact':
+        $default_vocab = 'tripal_contact';
+        $parent_term = 'TContact:0000001';
+        $description = 'Select the type.';
+        break;
+      default:
+        $description = t('Enter the name of the term that specifies the type. ' .
+            'The type must be the name of a term in a controlled vocabulary and ' .
+            'the controlled vocabulary should already be loaded into this site.');
+    }
     $info[$field_name] =  array(
       'field_name' => $field_name,
       'entity_type' => $entity_type,
       'bundle' => $bundle->name,
-      'label' => 'Publication Type',
-      'description' => 'Select the publication type.',
+      'label' => $label,
+      'description' => $description,
       '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',
+        'vocabulary' => $default_vocab,
+        'parent_term' => $parent_term,
       ),
       'widget' => array(
         'type' => 'schema__additional_type_widget',

+ 8 - 0
tripal_chado/tripal_chado.module

@@ -517,6 +517,14 @@ function tripal_chado_menu() {
     'file path' => drupal_get_path('module', 'tripal_chado'),
     'type' => MENU_CALLBACK,
   );
+  $items['admin/tripal/storage/chado/auto_name/cv/%'] = array(
+    'page callback' => 'tripal_autocomplete_cv',
+    'page arguments' => array(6),
+    'access arguments' => array('access content'),
+    'file' => 'api/modules/tripal_chado.cv.api.inc',
+    'file path' => drupal_get_path('module', 'tripal_chado'),
+    'type' => MENU_CALLBACK,
+  );
   $items['admin/tripal/storage/chado/auto_name/cvterm/%/%'] = array(
     'page callback' => 'tripal_autocomplete_cvterm',
     'page arguments' => array(6, 7),