View source
<?php
namespace Drupal\fillpdf_test\Plugin\PdfBackend;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\State\StateInterface;
use Drupal\file\FileInterface;
use Drupal\fillpdf\Plugin\PdfBackendBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class TestPdfBackend extends PdfBackendBase implements ContainerFactoryPluginInterface {
protected $configuration;
protected $state;
public function __construct(array $configuration, $plugin_id, array $plugin_definition, StateInterface $state) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->state = $state;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('state'));
}
public function parseFile(FileInterface $template_file) {
return $this
->parseStream('');
}
public function parseStream($pdf_content) {
return static::getParseResult();
}
public function mergeFile(FileInterface $template_file, array $field_mappings, array $context) {
return $this
->mergeStream('', $field_mappings, $context);
}
public function mergeStream($pdf_content, array $field_mappings, array $context) {
$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_mappings,
'context' => $context,
]);
return $populated_pdf;
}
public static function getParseResult() {
return [
0 => [
'name' => 'ImageField',
'value' => '',
'type' => 'Pushbutton',
],
1 => [
'name' => 'TestButton',
'value' => '',
'type' => 'Pushbutton',
],
2 => [
'name' => 'TextField1',
'value' => '',
'type' => 'Text',
],
3 => [
'name' => 'TextField2',
'value' => '',
'type' => 'Text',
],
4 => [
'name' => 'ImageField',
'value' => '',
'type' => 'Pushbutton',
],
];
}
}