Announcement

Collapse
No announcement yet.

Binding to extend PDF Printer

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Binding to extend PDF Printer

    Hi!

    I would like to override TcpdfEntityPrinter class with a custom class. PrinterController is instantiating TcpdfEntityPrinter.

    So I added:

    custom/Espo/Modules/Course/Binding.php
    PHP Code:
    namespace Espo\Modules\Course;

    use 
    Espo\Core\Binding\Binder;

    use 
    Espo\Tools\Pdf\Tcpdf\TcpdfEntityPrinter;
    use 
    Espo\Tools\Pdf\PrinterController;

    class 
    Binding
    {
    public function 
    process(Binder $binder)
    {
    $binder
    ->for(PrinterController::class)
    ->
    bindImplementation(TcpdfEntityPrinter::class, CustomEntityPrinter::class);
    }

    But my CustomEntityPrinter is not being used. Other bindings in this file are being used so it seems like I created the file correctly.

    custom/Espo/Modules/Course/CustomEntityPrinter.php
    PHP Code:
    namespace Espo\Modules\Course;

    ​class CustomEntityPrinter implements EntityPrinter
    {
    ....

    What am I doing wrong?
    Last edited by jeff11; 06-16-2023, 08:44 AM.

  • #2
    I figured it out!

    There is no need to do anything in Binding.php

    Adding an entry to Espo/Custom/Resources/metadata/app/pdfEngines.json like this will call your custom class:

    Code:
    {
    "Tcpdf": {
    "implementationClassNameMap": {
    "entity": "Espo\\Modules\\MyModule\\CustomTcpdfEntityPrinter"
    }
    }
    }
    ​
    I understand now:
    If you want to override a class that is being instantiated by $this->injectableFactory->create($className); you need to use metadata like above.
    If you want to override a class that is used in constructor like here https://docs.espocrm.com/development...entity-manager you need to use Binding.php

    Comment

    Working...
    X