function tripal_bulk_loader_edit_template_record_form
2.x tripal_bulk_loader.admin.templates.inc | tripal_bulk_loader_edit_template_record_form($form, &$form_state) |
3.x tripal_bulk_loader.admin.templates.inc | tripal_bulk_loader_edit_template_record_form( |
1.x tripal_bulk_loader.admin.templates.inc | tripal_bulk_loader_edit_template_record_form(&$form_state = NULL) |
Edit Record Form
D7 @todo: Needs to be debugged
This form is meant to be called from a bulk loader form. The following should be set in the query section of the path:
- template_id=\d+: the template which the edited record is part of
- record_id=\d+: the priority or key in the template array of the record to be edited
Parameters
$form_state: Contains the values and storage for the form
Return value
A form array to be rendered by drupal_get_form
Related topics
1 string reference to 'tripal_bulk_loader_edit_template_record_form'
- tripal_bulk_loader_menu in tripal_bulk_loader/
tripal_bulk_loader.module - Implements hook_menu().
File
- tripal_bulk_loader/
includes/ tripal_bulk_loader.admin.templates.inc, line 865 - All functions in this file pertain to administrative management of bulk loader templates
Code
function tripal_bulk_loader_edit_template_record_form($form, &$form_state) {
$form['#cache'] = TRUE; // Make sure the form is cached.
// get args from path
$template_id = (isset($form_state['build_info']['args'][0])) ? $form_state['build_info']['args'][0] : FALSE;
$form_state['storage']['template_id'] = $template_id;
$record_id = (isset($form_state['build_info']['args'][1])) ? $form_state['build_info']['args'][1] : FALSE;
$form_state['storage']['record_id'] = $record_id;
$form_state['values']['field_group'] = $record_id;
$form_state['storage']['original_priority'] = $record_id;
// if there is no template supplied don't return rest of form
if (!$template_id) {
return $form;
}
// set the breadcrumb
$breadcrumb = array();
$breadcrumb[] = l('Home', '<front>');
$breadcrumb[] = l('Administration', 'admin');
$breadcrumb[] = l('Tripal', 'admin/tripal');
$breadcrumb[] = l('Chado Data Loaders', 'admin/tripal/loaders');
$breadcrumb[] = l('Bulk Loader', 'admin/tripal/loaders/bulk');
$breadcrumb[] = l('Templates', 'admin/tripal/loaders/bulk/templates');
$breadcrumb[] = l('Edit Template', 'admin/tripal/loaders/bulk/template/' . $template_id . '/edit');
drupal_set_breadcrumb($breadcrumb);
// Pre-process values/defaults ---------------------------
// If this is the first load of the form (no form state) we need to initialize some variables
if (!array_key_exists('template', $form_state['storage'])) {
$sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=:template";
$template = db_query($sql, array(':template' => $template_id))->fetchObject();
$form_state['storage']['template_array'] = unserialize($template->template_array);
$form_state['storage']['template'] = $template;
// rebuild the record2priority array in the $form_state['storage'] array
$form_state['storage']['record2priority'] = array();
foreach ($form_state['storage']['template_array'] as $priority => $record_array) {
if (!is_array($record_array)) {
continue;
}
$form_state['storage']['record2priority'][$record_array['record_id']] = $priority;
}
$form_state['storage']['referring URL'] = $_SERVER["HTTP_REFERER"];
}
else {
$template = $form_state['storage']['template'];
}
// Tables and default table
$tables = chado_get_table_names(TRUE);
if (isset($form_state['values']['chado_table'])) {
$table = $form_state['values']['chado_table'];
}
else {
$table = $form_state['storage']['template_array'][$form_state['storage']['original_priority']]['table'];
}
// get the default mode
if (isset($form_state['storage']['original_priority'])) {
if (isset($form_state['storage']['template_array'][$form_state['storage']['original_priority']]['mode'])) {
$mode = $form_state['storage']['template_array'][$form_state['storage']['original_priority']]['mode'];
}
else {
$mode = 'insert';
}
// get default for the select optional
if (isset($form_state['storage']['template_array'][$form_state['storage']['original_priority']]['select_optional'])) {
$select_optional = $form_state['storage']['template_array'][$form_state['storage']['original_priority']]['select_optional'];
}
else {
$select_optional = 0;
}
// get default for the select if duplicate
if (isset($form_state['storage']['template_array'][$form_state['storage']['original_priority']]['select_if_duplicate'])) {
$select_if_duplicate = $form_state['storage']['template_array'][$form_state['storage']['original_priority']]['select_if_duplicate'];
}
else {
$select_if_duplicate = 0;
}
// get default for the update if duplicate
if (isset($form_state['storage']['template_array'][$form_state['storage']['original_priority']]['update_if_duplicate'])) {
$update_if_duplicate = $form_state['storage']['template_array'][$form_state['storage']['original_priority']]['update_if_duplicate'];
}
else {
$update_if_duplicate = 0;
}
// get default for the select if duplicate
if (isset($form_state['storage']['template_array'][$form_state['storage']['original_priority']]['optional'])) {
$optional = $form_state['storage']['template_array'][$form_state['storage']['original_priority']]['optional'];
}
else {
$optional = 0;
}
// get the default for disabling the record
if (isset($form_state['storage']['template_array'][$form_state['storage']['original_priority']]['disable'])) {
$disable = $form_state['storage']['template_array'][$form_state['storage']['original_priority']]['disable'];
}
else {
$disable = 0;
}
}
else {
$mode = 'insert';
$select_optional = 0;
$select_if_duplicate = 1;
$update_if_duplicate = 0;
$optional = 0;
$disable = 0;
}
// this is just for backwards compatibility. the insert_unique mode type is no longer available
if (strcmp($mode, 'insert_unique') == 0) {
$mode = 'insert';
$select_if_duplicate = 1;
}
// this is just for backwards compatibility. the insert_unique mode type is no longer available
if (strcmp($mode, 'optional') == 0) {
$mode = 'insert';
$optional = 1;
}
// Form Proper -------------------------------------------
$form['template_name'] = array(
'#type' => 'item',
'#title' => 'Template',
'#markup' => $template->name,
);
$form['template_id'] = array(
'#type' => 'hidden',
'#value' => $template_id,
);
$form['edit_record'] = array(
'#type' => 'markup',
);
// check template array for records then add one more
if (!$form_state['storage']['record2priority']) {
$groups = array();
}
else {
$groups = array_flip($form_state['storage']['record2priority']);
}
$priority_default = $form_state['values']['field_group'];
$form['edit_record']['field_group'] = array(
'#type' => 'select',
'#title' => 'Record',
'#description' => 'By Changing the record here, you can move all the fields from the current record into the selected record.',
'#options' => $groups,
'#default_value' => $priority_default,
'#required' => TRUE,
);
$form['edit_record']['record_name'] = array(
'#type' => 'textfield',
'#title' => 'Unique Record Name',
'#default_value' => $groups[$priority_default],
);
$form['edit_record']['chado_table'] = array(
'#type' => 'select',
'#title' => t('Chado Table'),
'#description' => 'This changes the chado table for all fields in this record.',
'#options' => $tables,
'#default_value' => $table,
);
$form['edit_record']['mode'] = array(
'#type' => 'radios',
'#title' => 'Action to take when Loading Record',
'#options' => array(
'select' => 'SELECT: Don\'t insert this record: it\'s used to define a foreign key in another record',
'select_once' => 'SELECT ONCE: Select the record only once for each constant set.',
'insert' => 'INSERT: Insert the record',
'insert_once' => 'INSERT ONCE: Record will be inserted once for each constant set. If the record is the same across multiple constant sets, make sure to select "SELECT if duplicate" as well.',
),
'#default_value' => $mode
);
$form['edit_record']['select_options'] = array(
'#type' => 'markup',
'#markup' => t('Additional Select Options:'),
);
$form['edit_record']['select_optional'] = array(
'#type' => 'checkbox',
'#title' => t('Continue if no record exists or too many exist.'),
'#description' => t('By default if a select does not find a match the loader will fail, or if it finds too many matches it will fail. Check here to allow the loader to continue when no match is found. In either case no value is passed on.'),
'#default_value' => $select_optional
);
$form['edit_record']['insert_options'] = array(
'#type' => 'markup',
'#prefix' => '<br>',
'#markup' => t('Additional Insert Options:'),
);
$form['edit_record']['select_if_duplicate'] = array(
'#type' => 'checkbox',
'#title' => t('SELECT if duplicate (no insert)'),
'#description' => t('If this is not the first time this record has been added then perform a select rather than an insert.'),
'#default_value' => $select_if_duplicate
);
$form['edit_record']['update_if_duplicate'] = array(
'#type' => 'checkbox',
'#title' => t('UPDATE if duplicate (no insert)'),
'#description' => t('If this is not the first time this record has been added then perform an update rather than an insert.'),
'#default_value' => $update_if_duplicate
);
$form['edit_record']['optional'] = array(
'#type' => 'checkbox',
'#title' => t('Optional'),
'#description' => t('The insert, update or select will only be performed only if all required data are present'),
'#default_value' => $optional
);
$form['edit_record']['disable'] = array(
'#type' => 'checkbox',
'#title' => t('Disable this record'),
'#description' => t("Check this box to ignore this record (not perform select or insert) during template loading. Uncheck to re-enable the record"),
'#default_value' => $disable,
);
$form['edit_record']['submit-edit_record'] = array(
'#type' => 'submit',
'#value' => 'Save Record'
);
$form['edit_record']['submit-cancel'] = array(
'#type' => 'submit',
'#value' => 'Cancel'
);
return $form;
}