function tripal_cv_add_cvterm_form_fields

2.x tripal_cv.cvterm_form.inc tripal_cv_add_cvterm_form_fields(&$form, $form_state, $cv_id = 0, $cvterm_name = '')
3.x tripal_chado.cv.inc tripal_cv_add_cvterm_form_fields(&$form, $form_state, $cv_id = 0, $cvterm_name = '')

Form fields in common between add/edit forms

Related topics

2 calls to tripal_cv_add_cvterm_form_fields()
tripal_cv_cvterm_add_form in tripal_cv/includes/tripal_cv.cvterm_form.inc
Form for adding cvterms
tripal_cv_cvterm_edit_form in tripal_cv/includes/tripal_cv.cvterm_form.inc
Form for editing cvterms

File

tripal_cv/includes/tripal_cv.cvterm_form.inc, line 170
Provides a form for creating & editing chado controlled vocabularies

Code

function tripal_cv_add_cvterm_form_fields(&$form, $form_state, $cv_id = 0, $cvterm_name = '') {

  $name = '';
  $definition = '';
  $is_relationship = '';
  $is_obsolete = '';
  $db_id = '';
  $accession = '';

  // get default values
  if ($cvterm_name) {
    $values = array('cv_id' => $cv_id, 'name' => $cvterm_name);
    $cvterm = chado_generate_var('cvterm', $values);
    $name = $cvterm->name;
    $definition = $cvterm->definition;
    $is_relationship = $cvterm->is_relationshiptype;
    $is_obsolete = $cvterm->is_obsolete;
    $db_id = $cvterm->dbxref_id->db_id->db_id;
    $accession = $cvterm->dbxref_id->accession;
  }

  // add a fieldset for the Drupal Schema API
  $form['fields'] = array(
    '#type' => 'fieldset',
    '#title' => 'Term Details',
    '#collapsible' => 0,
  );


  $form['fields']['name'] = array(
    '#type' => 'textfield',
    '#title' => t("Term Name"),
    '#default_value' => $name,
    '#description' => t('The term must be unique within the database selected below.'),
    '#required' => TRUE,
  );

  $form['fields']['definition'] = array(
    '#type' => 'textarea',
    '#title' => t('Description'),
    '#description' => t('Please enter a description for this term'),
    '#default_value' => $definition,
  );

  $form['fields']['is_relationship'] = array(
    '#type' => 'checkbox',
    '#title' => t('This term describes a relationship?'),
    '#default_value' => $is_relationship,
  );

  $form['fields']['is_obsolete'] = array(
    '#type' => 'checkbox',
    '#title' => t('This term is obsolete?'),
    '#default_value' => $is_obsolete,
  );

  $values = array();
  $columns = array('db_id', 'name');
  $options = array('order_by' => array('name' => 'ASC'));
  $results = chado_select_record('db', $columns, $values, $options);
  $dbs = array();
  $dbs[] = '';
  foreach ($results as $db) {
    $dbs[$db->db_id] = $db->name;
  }
  $form['fields']['db_id'] = array(
    '#type' => 'select',
    '#title' => t('Database'),
    '#description' => t('All terms must be assocated with a database. If there is no database for this term (e.g. it is a custom term specific to this site) then select the database \'null\' or consider creating a database specific for your site and use that anytime you would like to add terms.'),
    '#options' => $dbs,
    '#default_value' => $db_id,
    '#required' => TRUE,
  );

  $form['fields']['accession'] = array(
    '#type' => 'textfield',
    '#title' => t("Accession"),
    '#description' => t('If this term has an existing accession (unique identifier) in the database
       please enter that here.  If the accession is numeric with a database prefix (e.g. GO:003023), please
       enter just the numeric value.  The database prefix will be appended whenever the term is displayed.
       If you do not have a numeric value consider entering the term name as the accession.'),
    '#required' => TRUE,
    '#default_value' => $accession,
  );
}