@@ -203,14 +203,30 @@ class FillPdfOverviewForm extends FillPdfAdminFormBase {
...
@@ -203,14 +203,30 @@ class FillPdfOverviewForm extends FillPdfAdminFormBase {
// Attempt to parse the fields in the PDF.
// Attempt to parse the fields in the PDF.
$fields=$backend->parse($fillpdf_form);
$fields=$backend->parse($fillpdf_form);
$form_fields=[];
foreach((array)$fieldsas$key=>$arr){
if($arr['type']){// Don't store "container" fields
$arr['name']=str_replace('�','',$arr['name']);// pdftk sometimes inserts random � markers - strip these out. NOTE: This may break forms that actually DO contain this pattern, but 99%-of-the-time functionality is better than merge failing due to improper parsing.
$field=FillPdfFormField::create(
[
'fillpdf_form'=>$fillpdf_form,
'pdf_key'=>$arr['name'],
'value'=>'',
]
);
$form_fields[]=$field;
}
}
// Save the fields that were parsed out (if any). If none were, set a
// Save the fields that were parsed out (if any). If none were, set a
// warning message telling the user that.
// warning message telling the user that.
foreach($fieldsas$fillpdf_form_field){
foreach($form_fieldsas$fillpdf_form_field){
/** @var FillPdfFormField $fillpdf_form_field */
/** @var FillPdfFormField $fillpdf_form_field */
$fillpdf_form_field->save();
$fillpdf_form_field->save();
}
}
if(count($fields)===0){
if(count($form_fields)===0){
drupal_set_message($this->t('No fields detected in PDF. Are you sure it contains editable fields?'),'warning');
drupal_set_message($this->t('No fields detected in PDF. Are you sure it contains editable fields?'),'warning');
// TODO: Don't do magic error handling. Throw an exception and let the caller decide what to do. Make my own exception class (see PluginNotFoundException for inspiration).
if($result->error==TRUE){
// if ($result->error == TRUE) {
// @todo: Throw an exception, log a message etc.
//drupal_goto('admin/structure/fillpdf');
return[];
// } // after setting error message
}// after setting error message
$fields=$result->data;
$fields=$result->data;
$form_fields=array();
return$fields;
foreach((array)$fieldsas$key=>$arr){
if($arr['type']){// Don't store "container" fields
$arr['name']=str_replace('�','',$arr['name']);// pdftk sometimes inserts random � markers - strip these out. NOTE: This may break forms that actually DO contain this pattern, but 99%-of-the-time functionality is better than merge failing due to improper parsing.