9. For programmers and developers
This section is aimed at programmers who want to influence this extension in their own modules.
Internal field variables for PDF
New in version 2.3 are internal field variables that can be entered via the pdf_formsBeforePdf hook. These variables can then be used in exactly the same way as form fields from the submitted form. To be able to use these variables in the conditions, an entry must be made in config/config.yaml so that these fields are added to the conditions SELECT:
# config/config.yaml
softleister_pdfforms:
add_condition_options: [foo, bar]
In the example, the field variables foo and bar are made available for conditions. After entering them in the config.yaml file, the Symfony cache must be cleared/refreshed.
The variables and their values are then created in the pdf_formsBeforePdf hook (see below).
Hooks
In the program flow, you can link in at various points using a HOOK registration. The extension contao-pdfforms-bundle calls the registered hooks, if any are available.registered.
The following hooks are available:
pdf_formsBeforePdf
Is called after data preparation before the PDF is created. Here, further entries can be added to the $arrPDF array or existing entries can be modified. The hook must return the $arrPDF as the return value.
Example:
// src/EventListener/Pdf_formsBeforePdfListener.php
<?php
namespace App\EventListener;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
#[AsHook('pdf_formsBeforePdf')]
class Pdf_formsBeforePdfListener
{
public function __invoke(array $arrPDF)
{
// any code
return $arrPDF;
}
}
pdf_formsPositions
Is called up for each item in the form during PDF creation. It is still possible to maniĀpulate data here. The page number cannot be changed, otherwise the output will not work correctly. The passed and possibly modified array $arrItem is expected as the return value.
Example:
// src/EventListener/Pdf_formsPositionsListener.php
<?php
namespace App\EventListener;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
#[AsHook('pdf_formsPositions')]
class Pdf_formsPositionsListener
{
public function __invoke(array $arrItem)
{
// any code
return $arrItem;
}
}
pdf_formsAfterPdf
Is called up after creation, saving and transfer to form processing. Further final activities can be inserted here using a hook. The hook has no return value.
Example:
// src/EventListener/Pdf_formsAfterPdfListener.php
<?php
namespace App\EventListener;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
#[AsHook('pdf_formsAfterPdf')]
class Pdf_formsAfterPdfListener
{
public function __invoke(string $pdfdatei, array $arrPDF): void
{
// any code
}
}