function chado_featuremap_form

2.x tripal_featuremap.chado_node.inc chado_featuremap_form($node, &$form_state)
3.x tripal_featuremap.chado_node.inc chado_featuremap_form($node, &$form_state)
1.x tripal_featuremap.form.inc chado_featuremap_form($node)

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

Related topics

File

tripal_featuremap/includes/tripal_featuremap.chado_node.inc, line 45
Hooks implementing the feature map node content type

Code

function chado_featuremap_form($node, &$form_state) {
  $form = array();

  // Default values can come in the following ways:
  //
  // 1) as elements of the $node object.  This occurs when editing an existing library
  // 2) in the $form_state['values'] array which occurs on a failed validation or
  //    ajax callbacks from non submit form elements
  // 3) in the $form_state['input'[ array which occurs on ajax callbacks from submit
  //    form elements and the form is being rebuilt
  //
  // set form field defaults
  $featuremap_id = NULL;
  $fmapname = '';
  $description = '';
  $unittype_id = '';

  // if we are editing an existing node then the featuremap is already part of the node
  if (property_exists($node, 'featuremap')) {
    $featuremap = $node->featuremap;
    $featuremap = chado_expand_var($featuremap, 'field', 'featuremap.description');
    $featuremap_id = $featuremap->featuremap_id;

    // get form defaults
    $fmapname = $featuremap->name;
    $description = $featuremap->description;
    $unittype_id = $featuremap->unittype_id->cvterm_id;

    // set the featuremap_id in the form
    $form['featuremap_id'] = array(
      '#type' => 'hidden',
      '#value' => $featuremap_id,
    );
  }
  // if we are re constructing the form from a failed validation or ajax callback
  // then use the $form_state['values'] values
  if (array_key_exists('values', $form_state)) {
    $fmapname = $form_state['values']['fmapname'];
    $description = $form_state['values']['description'];
    $unittype_id = $form_state['values']['unittype_id'];
  }
  // if we are re building the form from after submission (from ajax call) then
  // the values are in the $form_state['input'] array
  if (array_key_exists('input', $form_state) and !empty($form_state['input'])) {
    $fmapname = $form_state['input']['fmapname'];
    $description = $form_state['input']['description'];
    $unittype_id = $form_state['input']['unittype_id'];
  }

  $form['fmapname'] = array(
    '#type' => 'textfield',
    '#title' => t('Map Name'),
    '#description' => t('Please enter a name for this map'),
    '#required' => TRUE,
    '#default_value' => $fmapname,
    '#maxlength' => 255
  );
  $form['description'] = array(
    '#type' => 'text_format',
    '#title' => t('Map Description'),
    '#description' => t('A description of the map.'),
    '#required' => TRUE,
    '#default_value' => $description,
  );

  // get the list of unit types
  $units = tripal_get_cvterm_default_select_options('featuremap', 'unittype_id', 'map unit types');

  $form['unittype_id'] = array(
    '#title' => t('Map Units'),
    '#type' => t('select'),
    '#description' => t("Chose the units for this map"),
    '#required' => TRUE,
    '#default_value' => $unittype_id,
    '#options' => $units,
  );

  // Properties Form
  // ----------------------------------
  $prop_cv = tripal_get_default_cv('featuremap_property', 'type_id');
  $cv_id = $prop_cv ? $prop_cv->cv_id : NULL;
  $instructions = t('To add additional properties to the drop down. ' . l("Add terms to the featuremap_property vocabulary", "admin/tripal/chado/tripal_cv/cvterm/add") . ".");
  $details = array(
    'property_table' => 'featuremapprop',
    'chado_id' => $featuremap_id,
    'cv_id' => $cv_id,
    'fieldset_name' => 'Additional Details',
    'additional_instructions' => $instructions
  );
  // TODO: remove the 'Map Dbxref' from the list as that should now be handled
  // by the dbxref interface below
  chado_add_node_form_properties($form, $form_state, $details);

  // ADDITIONAL DBXREFS FORM
  //---------------------------------------------
  $details = array(
    'linking_table' => 'featuremap_dbxref', // the name of the _dbxref table
    'base_foreign_key' => 'featuremap_id', // the name of the key in your base chado table
    'base_key_value' => $featuremap_id // the value of featuremap_id for this record
  );
  // Adds the form elements to your current form
  chado_add_node_form_dbxrefs($form, $form_state, $details);

  return $form;
}