function tripal_cv_cvterm_edit_form
2.x tripal_cv.cvterm_form.inc | tripal_cv_cvterm_edit_form($form, &$form_state) |
3.x tripal_chado.cv.inc | tripal_cv_cvterm_edit_form($form, &$form_state) |
Form for editing cvterms
Related topics
1 string reference to 'tripal_cv_cvterm_edit_form'
- tripal_cv_menu in tripal_cv/
tripal_cv.module - Implements hook_menu(). Registers all menu items associated with this module
File
- tripal_cv/
includes/ tripal_cv.cvterm_form.inc, line 12 - Provides a form for creating & editing chado controlled vocabularies
Code
function tripal_cv_cvterm_edit_form($form, &$form_state) {
$step = 0;
if (empty($form_state['storage']['step'])) {
$form_state['storage']['step'] = 0;
}
else {
$step = $form_state['storage']['step'];
}
$cv_id = 0;
if ($step == 1) {
$cv_id = $form_state['storage']['cv_id'];
$cvterm_name = $form_state['storage']['name'];
$cvterm_id = $form_state['storage']['cvterm_id'];
}
// get the cv if form was submitted via AJAX
$cvterm = '';
if (array_key_exists('values', $form_state)) {
$cv_id = $form_state['values']['cv_id'];
if (array_key_exists('cvterm', $form_state['values'])) {
$cvterm = $form_state['values']['cvterm'];
}
}
elseif (isset($form_state['build_info']['args'][0])) {
$cv_id = $form_state['build_info']['args'][0];
$cvterm_id = $form_state['build_info']['args'][1];
if ($form_state['build_info']['args'][1]) {
$cvterm_name = chado_query('SELECT name FROM {cvterm} WHERE cvterm_id=:id', array(':id' => $cvterm_id))->fetchField();
$step = 1;
}
}
// get a list of CVs
$cvs = array();
$sql = "SELECT * FROM {cv} WHERE NOT name = 'tripal' ORDER BY name ";
$results = chado_query($sql);
$cvs[] = 'Select a vocabulary';
foreach ($results as $cv) {
$cvs[$cv->cv_id] = $cv->name;
}
$form['cv_id'] = array(
'#title' => t('Controlled Vocabulary (Ontology) Name'),
'#type' => 'select',
'#options' => $cvs,
'#required' => TRUE,
'#default_value' => $cv_id,
'#ajax' => array(
'callback' => 'tripal_cv_cvterm_edit_form_ajax',
'wrapper' => 'cvterm-edit-div',
'event' => 'change',
'method' => 'replace',
'event' => 'change',
),
);
if ($cv_id and $step == 0) {
$form['name'] = array(
'#type' => 'textfield',
'#title' => t("Term Name"),
'#default_value' => $cvterm,
'#required' => TRUE,
'#autocomplete_path' => "admin/tripal/tripal_cv/cvterm/auto_name/$cv_id",
'#description' => t('Enter the term to edit.')
);
$form['continue'] = array(
'#type' => 'submit',
'#value' => 'continue',
);
}
elseif ($step == 1) {
tripal_cv_add_cvterm_form_fields($form, $form_state, $cv_id, $cvterm_name);
// when editing there are certain fields the user should not change for a term
// let's mark those as disabled
$form['cv_id']['#disabled'] = TRUE;
$form['fields']['db_id']['#disabled'] = TRUE;
$form['fields']['accession']['#disabled'] = TRUE;
// add in the div for replacing the fields if needed
$form['fields']['#prefix'] = '<div id="cvterm-edit-div">';
$form['fields']['#suffix'] = '</div>';
// add in the cvterm id
$form['fields']['cvterm_id'] = array(
'#type' => 'hidden',
'#value' => $cvterm_id,
);
$form['update'] = array(
'#type' => 'submit',
'#value' => t('Update'),
);
$form['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
'#attributes' => array('onclick' => 'if(!confirm("Really Delete?")){return false;}'),
);
}
if ($step == 0) {
// if we don't have a cv_id then this is the first time the form has
// benn loaded and we need to create the div where ajax replacement elements get stored
$form['div_replace'] = array(
'#type' => 'item',
'#prefix' => '<div id="cvterm-edit-div">',
'#suffix' => '</div>',
);
}
return $form;
}