Skip to content
Snippets Groups Projects
Commit 096ea16a authored by pancho's avatar pancho Committed by Liam Morland
Browse files

Issue #3023330 by Pancho, Liam Morland: Consolidate duplicate form field instances parsed by pdftk

parent 74585bfa
No related branches found
No related tags found
No related merge requests found
...@@ -1570,6 +1570,7 @@ function fillpdf_parse_pdf($fid) { ...@@ -1570,6 +1570,7 @@ function fillpdf_parse_pdf($fid) {
->execute(); ->execute();
// Create fields. // Create fields.
$unique_fields = array();
foreach ((array) $parsed_fields as $key => $field) { foreach ((array) $parsed_fields as $key => $field) {
// Don't store "container" fields. // Don't store "container" fields.
if (!empty($field['type'])) { if (!empty($field['type'])) {
...@@ -1580,13 +1581,19 @@ function fillpdf_parse_pdf($fid) { ...@@ -1580,13 +1581,19 @@ function fillpdf_parse_pdf($fid) {
// improper parsing. // improper parsing.
$field['name'] = str_replace('�', '', $field['name']); $field['name'] = str_replace('�', '', $field['name']);
$record = array( // Use the field name as key, so to consolidate duplicate fields.
'label' => NULL, $unique_fields[$field['name']] = TRUE;
'value' => '',
);
fillpdf_fields_create_update($fid, $field['name'], $record);
} }
} }
// 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') { ...@@ -1774,6 +1781,12 @@ function fillpdf_execute_parse($method, $fillpdf, $mode = 'url') {
'value' => '', 'value' => '',
'type' => 'Text', 'type' => 'Text',
), ),
// Test duplicate name.
3 => [
'name' => 'ImageField',
'value' => '',
'type' => 'Pushbutton',
],
); );
break; break;
} }
......
...@@ -40,6 +40,8 @@ trait FillPdfTestHelper { ...@@ -40,6 +40,8 @@ trait FillPdfTestHelper {
$this->drupalPost('admin/structure/fillpdf', array( $this->drupalPost('admin/structure/fillpdf', array(
'files[upload_pdf]' => drupal_realpath(drupal_get_path('module', 'fillpdf') . '/tests/fillpdf_test_v4.pdf'), 'files[upload_pdf]' => drupal_realpath(drupal_get_path('module', 'fillpdf') . '/tests/fillpdf_test_v4.pdf'),
), t('Upload')); ), 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.");
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment