You are here

public function TestFillPdfBackend::populateWithFieldData in FillPDF 8.4

Populate a FillPDF form with field data.

Formerly known as merging. Accept an array of PDF field keys and field values and populate the PDF using them.

Parameters

\Drupal\fillpdf\FillPdfFormInterface $fillpdf_form: The FillPdfForm referencing the file whose field values are going to be populated.

array $field_mapping: An array of fields mapping PDF field keys to the values with which they should be replaced. Example array:

[
  'values' => [
    'Field 1' => 'value',
    'Checkbox Field' => 'On',
  ],
  'images' => [
    'Image Field 1' => [
      'data' => base64_encode($file_data),
      'filenamehash' => md5($image_path_info['filename']) . '.' . $image_path_info['extension'],
    ],
  ],
];

array $context: The request context as returned by FillPdfLinkManipulatorInterface::parseLink().

Return value

string|null The raw file contents of the new PDF, or NULL if populating failed. The caller has to handle saving or serving the file accordingly.

Overrides FillPdfBackendPluginInterface::populateWithFieldData

File

tests/modules/fillpdf_test/src/Plugin/FillPdfBackend/TestFillPdfBackend.php, line 74

Class

TestFillPdfBackend
Backend used in tests.

Namespace

Drupal\fillpdf_test\Plugin\FillPdfBackend

Code

public function populateWithFieldData(FillPdfFormInterface $pdf_form, array $field_mapping, array $context) {

  // Not really populated, but that isn't our job.
  $populated_pdf = file_get_contents(drupal_get_path('module', 'fillpdf_test') . '/files/fillpdf_test_v3.pdf');
  $this->state
    ->set('fillpdf_test.last_populated_metadata', [
    'field_mapping' => $field_mapping,
    'context' => $context,
  ]);
  return $populated_pdf;
}