function chado_stock_form

2.x tripal_stock.chado_node.inc chado_stock_form($node, $form_state)
3.x tripal_stock.chado_node.inc chado_stock_form($node, $form_state)
1.x tripal_stock.module chado_stock_form($node, $form_state)

Implements hook_form(): Creates the main Add/Edit/Delete Form for chado stocks

Parts to be added by this form name, uniquename, description, type => select from cvterm with key cvterm_id, organism => select from available with key organism_id main_db_reference => accession, version, description, db_name(select from dropdown)

Parameters

$node: An empty node object on insert OR the current stock node object on update

$form_state: The current state of the form

Return value

A description of the form to be rendered by drupal_get_form()

Related topics

File

tripal_stock/tripal_stock.module, line 417
Implements Tripal Stock Module hooks

Code

function chado_stock_form($node, $form_state) {

  // Expand all fields needed
  $fields_needed = array('stock.uniquename', 'stock.name', 'stock.stock_id', 'stock.type_id', 'stock.organism_id', 'stock.description', 'stock.dbxref_id', 'dbxref.accession', 'dbxref.description', 'dbxref.db_id', 'db.db_id');
  foreach ($fields_needed as $field_name) {
    // Check to see if it's excluded and expand it if so
    if ($node->expandable_fields) {
      if (in_array($field_name, $node->expandable_fields)) {
        $node = tripal_core_expand_chado_vars($node, 'field', $field_name);
      }
    }
  }

  // This defines the path for the next step in a simulated multipart form
  // NOTE: The %node gets replaced with the nid in insert
  $form['next_step_path'] = array(
    '#type' => 'hidden',
    '#value' => 'node/%node/properties'
  );

  // If you don't want a multipart form set this to false
  // Will then do default redirect (to new node) on submit
  $form['simulate_multipart'] = array(
    '#type' => 'textfield',
    '#attributes' => array('style' => "display:none"),
    '#default_value' => TRUE
  );

  if (!isset($node->stock->uniquename)) {
    $form['progress'] = array(
      '#type' => 'item',
      '#value' => tripal_stock_add_chado_properties_progress('main')
    );
  }

  $form['names'] = array(
    '#type' => 'fieldset',
    '#title' => t('Stock Name')
  );

  $form['names']['sname'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#default_value' => $node->stock->name,
    '#required' => TRUE
  );

  $form['names']['uniquename'] = array(
    '#type' => 'textfield',
    '#title' => t('Unique Name'),
    '#default_value' => $node->stock->uniquename,
    '#required' => TRUE
  );

  $form['names']['stock_id'] = array(
    '#type' => 'hidden',
    '#value' => $node->stock->stock_id
  );

  $form['details'] = array(
    '#type' => 'fieldset',
    '#title' => t('Stock Details')
  );

  $type_options = tripal_cv_get_cvterm_options(variable_get('chado_stock_types_cv', 'NULL'));
  $type_options[0] = 'Select a Type';
  if ($node->nid == '') {
    $type_default = 0;
  }
  else {
    $type_default = $node->stock->type_id->cvterm_id;
  }
  $form['details']['type_id'] = array(
    '#type' => 'select',
    '#title' => t('Type of Stock'),
    '#options' => $type_options,
    '#default_value' => $type_default,
    '#required' => TRUE,
  );


  // get the list of organisms
  $sql = "SELECT * FROM {Organism} ORDER BY genus, species";
  $org_rset = chado_query($sql);
  $organisms = array();
  $organisms[''] = '';
  while ($organism = db_fetch_object($org_rset)) {
    $organisms[$organism->organism_id] = "$organism->genus $organism->species ($organism->common_name)";
  }
  $form['details']['organism_id'] = array(
    '#type' => 'select',
    '#title' => t('Source Organism for stock'),
    '#default_value' => $node->stock->organism_id->organism_id,
    '#options' => $organisms,
    '#required' => TRUE
  );


  $form['details']['stock_description'] = array(
    '#type' => 'textarea',
    '#title' => t('Notes'),
    '#default_value' => $node->stock->description,
    '#description' => t('Briefly enter any notes on the above stock. This should not include phenotypes or genotypes.'),
  );

  $form['database_reference'] = array(
    '#type' => 'fieldset',
    '#title' => t('Stock Database Reference')
  );

  $form['database_reference']['accession'] = array(
    '#type' => 'textfield',
    '#title' => t('Accession'),
    '#default_value' => $node->stock->dbxref_id->accession
  );

  $form['database_reference']['db_description'] = array(
    '#type' => 'textarea',
    '#title' => t('Description of Database Reference'),
    '#default_value' => $node->stock->dbxref_id->description,
    '#description' => t('Optionally enter a description about the database accession.')
  );

  $db_options = tripal_db_get_db_options();
  $db_options[0] = 'Select a Database';
  if ($node->nid == '') {
    $db_default = 0;
  }
  else {
    $db_default = $node->stock->dbxref_id->db_id->db_id;
  }
  $form['database_reference']['database'] = array(
    '#type' => 'select',
    '#title' => t('Database'),
    '#options' => $db_options,
    '#default_value' => $db_default
  );

  return $form;
}