function chado_library_form

2.x tripal_library.chado_node.inc chado_library_form($node, &$form_state)
3.x tripal_library.chado_node.inc chado_library_form($node, &$form_state)
1.x tripal_library.module chado_library_form($node)

When editing or creating a new node of type 'chado_library' we need a form. This function creates the form that will be used for this.

Related topics

File

tripal_library/tripal_library.module, line 424

Code

function chado_library_form($node) {
  $form = array();

  $library = $node->library;

  // get the default values
  $uniquename = $node->uniquename;
  if (!$uniquename) {
    $uniquename = $library->uniquename;
  }
  $library_type = $node->library_type;
  if (!$library_type) {
    $library_type = $library->type_id->cvterm_id;
  }
  $organism_id = $node->organism_id;
  if (!$organism_id) {
    $organism_id = $library->organism_id->organism_id;
  }
  $library_description = $node->library_description;
  if (!$library_description) {
    $libprop = tripal_library_get_property($library->library_id, 'library_description');
    $library_description = $libprop->value;
  }

  // keep track of the library id if we have.  If we do have one then
  // this is an update as opposed to an insert.
  $form['library_id'] = array(
    '#type' => 'value',
    '#value' => $library->library_id,
  );

  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Library Title'),
    '#description' => t('Please enter the title for this library. ' .
      'This appears at the top of the library page.'),
    '#required' => TRUE,
    '#default_value' => $node->title,
    '#weight' => 1
  );

  $form['uniquename'] = array(
    '#type' => 'textfield',
    '#title' => t('Unique Library Name'),
    '#description' => t('Please enter a unique name for this library'),
    '#required' => TRUE,
    '#default_value' => $uniquename,
    '#weight' => 2
  );

  // get the list of library types
  $values = array(
    'cv_id' => array(
      'name' => 'tripal_library_types',
    )
  );
  $columns = array('cvterm_id', 'name');
  $options = array('order_by' => array('name' => 'ASC'));
  $lib_types = tripal_core_chado_select('cvterm', $columns, $values, $options);
  $types = array();
  $types[''] = '';
  foreach ($lib_types as $type) {
    $types[$type->cvterm_id] = $type->name;
  }

  $form['library_type'] = array(
    '#title' => t('Library Type'),
    '#type' => t('select'),
    '#description' => t("Choose the library type."),
    '#required' => TRUE,
    '#default_value' => $library_type,
    '#options' => $types,
    '#weight' => 3
  );

  // get the list of organisms
  $sql = "SELECT * FROM {Organism}";
  $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['organism_id'] = array(
    '#title' => t('Organism'),
    '#type' => t('select'),
    '#description' => t("Choose the organism with which this library is " .
      "associated."),
    '#required' => TRUE,
    '#default_value' => $organism_id,
    '#options' => $organisms,
    '#weight' => 4,
  );

  $form['library_description'] = array(
    '#type' => 'textarea',
    '#title' => t('Library Description'),
    '#description' => t('A brief description of the library'),
    '#required' => TRUE,
    '#default_value' => $library_description,
    '#weight' => 5
  );

  return $form;
}