Create Extension for V8.10.1 for BasePDFManager.php Changes

I am trying to build an extension for upgrade-safe as not to edit core file BasePDFManager.php
I am trying to change the PDF file name.
I can edit the BasePDFManager file and it works.
I can’t get it to work with the extension.
Here is my extension.php for registering the extension-

use Symfony\Component\DependencyInjection\Container;

if (!isset($container)) {
return;
}

/** @var Container $container */
$extensions = $container->getParameter(‘extensions’) ?? ;

$extensions[‘NewPdfName’] = [
‘remoteEntry’ => ‘../extensions/NewPdfName/remoteEntry.js’,
‘remoteName’ => ‘NewPdfName’,
‘enabled’ => true,

Here is my namespace file (PdfHandler.php)-

namespace App\Extension\NewPdfName\backend;

use App\backend\Proces\LegacyHandler\Pdf\BasePDFManager;
use App\Engine\LegacyHandler\LegacyHandler;
use App\Process\Service\ProcessHandlerInterface;
use App\Data\Service\Record\RecordSaveHandlers\RecordSaveHandlerInterface;

class PdfHandler extends BasePDFManager implements LegacyHandler
{

// Your business logic here

public function run($fileName, $moduleBean)
{

$fileName = $this->getPdfName($moduleBean->name, $moduleBean->project_c); 
$fileName = str_replace('_', '-', $fileName);

}

}

My extension get registered but does not execute when I print-as-PDF on an invoice.
Can you tell me what I an not doing or doing wrong?
I am not use to working with the new Symfony structure.

Don’t guess anyone knows how to create an extension for the new Symfony V8.10.1.
I will have to edit core file BasePDFManager.php and change it every time I make an update.

Im not sure you need to do that, I think after looking at the code you can edit the vardefs record for the print as pdf link to include a params section that includes an option “fileNaming” set this to “template” and it will use the template name (replace spaces with _ and add .pdf). In fact the Accounts detailviewdefs.php shows a sample of this:

'recordActions' => [
    'actions' => [
        'print-as-pdf' => [
            'key' => 'print-as-pdf',
            'labelKey' => 'LBL_PRINT_AS_PDF',
            'asyncProcess' => true,
            'modes' => ['detail'],
            'acl' => ['view'],
            'aclModule' => 'AOS_PDF_Templates',
            'params' => [
                'createNote' => true,
                'fileNaming' => 'template',
                'selectModal' => [
                    'module' => 'AOS_PDF_Templates'
                ]
            ]
        ]
    ]
],

If you remove the fileNaming section OR change it to anything else it uses the Bean name itself.

The BasePdf is hardcoded into the service, about the only way to override this at this stage would be to create a new service (my-print-as-pdf) and replace all the buttons to use your service that calls your new Process.

Mark

Mark

1 Like