diff --git a/fillpdf.module b/fillpdf.module index 37d90f7eff1033016d341520a5950d1bf7c46e68..1a685919c5019d7690660adc15474d960ccddf59 100644 --- a/fillpdf.module +++ b/fillpdf.module @@ -1570,6 +1570,7 @@ function fillpdf_parse_pdf($fid) { ->execute(); // Create fields. + $unique_fields = array(); foreach ((array) $parsed_fields as $key => $field) { // Don't store "container" fields. if (!empty($field['type'])) { @@ -1580,13 +1581,19 @@ function fillpdf_parse_pdf($fid) { // improper parsing. $field['name'] = str_replace('�', '', $field['name']); - $record = array( - 'label' => NULL, - 'value' => '', - ); - fillpdf_fields_create_update($fid, $field['name'], $record); + // Use the field name as key, so to consolidate duplicate fields. + $unique_fields[$field['name']] = TRUE; } } + + // Save the fields that were parsed out (if any). + foreach (array_keys($unique_fields) as $pdf_key) { + $record = array( + 'label' => NULL, + 'value' => '', + ); + fillpdf_fields_create_update($fid, $pdf_key, $record); + } } /** @@ -1774,6 +1781,12 @@ function fillpdf_execute_parse($method, $fillpdf, $mode = 'url') { 'value' => '', 'type' => 'Text', ), + // Test duplicate name. + 3 => [ + 'name' => 'ImageField', + 'value' => '', + 'type' => 'Pushbutton', + ], ); break; } diff --git a/tests/FillPdfTestHelper.test b/tests/FillPdfTestHelper.test index dbee395b222f692041e148d28b9c994a4ae5e862..c8681cf730a7a7797a2c0a76bf616fd07038ddbe 100644 --- a/tests/FillPdfTestHelper.test +++ b/tests/FillPdfTestHelper.test @@ -40,6 +40,8 @@ trait FillPdfTestHelper { $this->drupalPost('admin/structure/fillpdf', array( 'files[upload_pdf]' => drupal_realpath(drupal_get_path('module', 'fillpdf') . '/tests/fillpdf_test_v4.pdf'), ), t('Upload')); + $this->assertText('fillpdf_test_v4.pdf was successfully uploaded.'); + $this->assertResponse(200, "The duplicate field is consolidated and doesn't lead to an integrity constraint violation."); } /**