Skip to content
Snippets Groups Projects
Commit 9118efe3 authored by Liam Morland's avatar Liam Morland
Browse files

Issue #3278852: Always display warning on FillPDF form page when there are no fillable fields

Rather than only when the PDF is uploaded and only when using the pdftk
backend.
parent 52a4a342
No related branches found
No related tags found
No related merge requests found
......@@ -138,6 +138,13 @@ class FillPdfFormForm extends ContentEntityForm {
/** @var \Drupal\fillpdf\FillPdfFormInterface $fillpdf_form */
$fillpdf_form = $this->entity;
$existing_fields = $fillpdf_form->getFormFields();
if (!count($existing_fields)) {
$fillpdf_form_fields_empty_message = $this->t('PDF does not contain fillable fields.');
$this->messenger()->addWarning($fillpdf_form_fields_empty_message);
}
$form['title']['token_tree'] = $this->adminFormHelper->getAdminTokenForm();
// @todo Encapsulate this logic into a ::getDefaultEntityType() method on FillPdfForm
......@@ -397,9 +404,22 @@ class FillPdfFormForm extends ContentEntityForm {
$form['user_password']['#group'] = 'security';
// @todo Add a button to let them attempt re-parsing if it failed.
$form['fillpdf_fields']['fields'] = FillPdf::embedView('fillpdf_form_fields',
'block_1',
$fillpdf_form->id());
if (count($existing_fields)) {
$form['fillpdf_fields']['fields'] = FillPdf::embedView('fillpdf_form_fields',
'block_1',
$fillpdf_form->id());
}
else {
$form['fillpdf_fields'] = [
'#theme' => 'status_messages',
'#message_list' => [
'warning' => [$fillpdf_form_fields_empty_message],
],
'#status_headings' => [
'warning' => t('Warning message'),
],
];
}
$form['fillpdf_fields']['#weight'] = 100;
......
......@@ -119,7 +119,6 @@ class PdftkPdfBackend extends PdfBackendBase implements ContainerFactoryPluginIn
$output = [];
exec("{$pdftk_path} {$template_path} dump_data_fields_utf8", $output, $status);
if (count($output) === 0) {
$this->messenger()->addWarning($this->t('PDF does not contain fillable fields.'));
return [];
}
......
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