Skip to content

Commit

Permalink
Merge pull request #1177 from tripal/1170-tv3-bulk_loader_fixes
Browse files Browse the repository at this point in the history
Bulk Loader Bug in Required Fields
  • Loading branch information
spficklin committed Mar 23, 2021
2 parents 29b3039 + 0dd757b commit dae8b84
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
28 changes: 25 additions & 3 deletions tripal_bulk_loader/includes/tripal_bulk_loader.admin.templates.inc
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,10 @@ function tripal_bulk_loader_modify_template_base_form($form, &$form_state = NULL
'#type' => 'hidden',
'#value' => $priority,
],
'required' => [
'#type' => 'item',
'#markup' => $field['required'] ? '✔' : '',
],
'field_name' => [
'#type' => 'item',
'#markup' => $field['title'],
Expand Down Expand Up @@ -1848,7 +1852,16 @@ function tripal_bulk_loader_template_field_form_default_values($mode, &$form_sta
$v['foreign_record'] = (isset($form_state['values']['foreign_record'])) ? $form_state['values']['foreign_record'] : 'NULL';
$v['foreign_field_options'] = $ref_chado_fields;
$v['foreign_field'] = (isset($form_state['values']['foreign_field'])) ? $form_state['values']['foreign_field'] : current($ref_chado_fields);
$v['required'] = (isset($form_state['values']['required'])) ? $form_state['values']['required'] : FALSE;

// The required checkbox should be forced as checked if this database
// column is set to 'not null'. Otherwise, use the form state.
if (array_key_exists('not null', $table_description['fields'][$field]) and
$table_description['fields'][$field]['not null'] === TRUE) {
$v['required'] = 'FORCE_TRUE';
}
else {
$v['required'] = (isset($form_state['values']['required'])) ? $form_state['values']['required'] : $template_field['required'];
}

if (isset($original_field['regex']) && empty($form_state['storage']['regex']['pattern'])) {
$form_state['storage']['regex']['pattern'] = $original_field['regex']['pattern'];
Expand Down Expand Up @@ -2169,6 +2182,16 @@ function tripal_bulk_loader_template_field_form($form, &$form_state = NULL) {
'#default_value' => $values['required'],
];

// If the required value is set as "FORCE_TRUE" then that means the
// underlying database column is set to NOT NULL so the end-user should
// not be able to change if this field is required or not.
if ($values['required'] === 'FORCE_TRUE') {
$form['fields']['field']['additional']['required']['#attributes']['disabled'] = TRUE;
$form['fields']['field']['additional']['required']['#value'] = 1;
$form['fields']['field']['additional']['required']['#default_value'] = 1;
$form['fields']['field']['additional']['required']['#title'] = 'The database constraints force this field to be required.';
}

$form['fields']['field']['additional']['regex_transform'] = [
'#type' => 'fieldset',
'#title' => 'Transform Data File Value Rules',
Expand All @@ -2188,7 +2211,7 @@ function tripal_bulk_loader_template_field_form($form, &$form_state = NULL) {
$pattern_default = '';
$replace_default = '';

// Check to see if there is more than one regex and if so warn them that
// Check to see if there is more than one regex and if so warn them that
// this feature is no longer supported. We don't want people to lose existing
// transformation rules just by tweaking the field so we will only set defaults
// if there is a single rule and summarize multiple rules statically.
Expand Down Expand Up @@ -2420,7 +2443,6 @@ function tripal_bulk_loader_template_field_form_submit($form, &$form_state) {
$form_state['rebuild'] = FALSE;
$form_state['redirect'] = 'admin/tripal/loaders/bulk/template/' . $form_state['storage']['template_id'] . '/edit';
}

}

/**
Expand Down
6 changes: 4 additions & 2 deletions tripal_bulk_loader/includes/tripal_bulk_loader.loader.inc
Original file line number Diff line number Diff line change
Expand Up @@ -528,14 +528,16 @@ function process_data_array_for_line($priority, &$data, &$default_data, $addt) {
}

// Check that template required fields are present. if a required field is
// missing and this
// is an optional record then just return. otherwise raise an error
// missing and this is an optional record then just return. otherwise raise
// an error
$skip_optional = 0;
foreach ($table_data['required'] as $field => $required) {

if ($required) {
// check if the field has no value (or array is empty)
if (!isset($values[$field]) or
(is_array($values[$field]) and count($values[$field]) == 0)) {

// check if the record is optional. For backwards compatiblity we need to
// check if the 'mode' is set to 'optional'
if ($table_data['optional'] or preg_match('/optional/', $table_data['mode']) or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
'Chado Field',
'Field Type',
'Field Settings',
'Required',
]; //'Data Column', 'Constant Value', 'Referred Record');
$rows = [];

// This is an array to keep track of the record => field index as well as the number of fields.
// It is used to make the record column span all the field rows providing more room for
// It is used to make the record column span all the field rows providing more room for
// information and a visual separation between records.
// Expect: record_id => array(index1, index2, index3)
$field_record = [];
Expand Down Expand Up @@ -81,10 +82,15 @@
'class' => ['field-type'],
];

// Finally specify the field value.

// Specify the field value.
$row[] = $value;

// Specify if the field is required.
$row[] = [
'data' => drupal_render($row_element['required']),
'class' => ['field-required'],
];

// Add this field to the table.
$rows[] = [
'class' => [$type_class],
Expand Down
3 changes: 3 additions & 0 deletions tripal_bulk_loader/theme/tripal_bulk_loader.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
text-align: center;
width: 50px;
}
#tripal-bulk-loader-modify-template-base-form td.field-required {
text-align: center;
}
#tripal-bulk-loader-modify-template-base-form td.record {
width: 100px;
background-color: #F2F3ED;
Expand Down

0 comments on commit dae8b84

Please sign in to comment.