From 8fd0e3e29852fb59564d52a34e01bb5a173e76e3 Mon Sep 17 00:00:00 2001 From: Lennart Fries Date: Thu, 21 Dec 2023 10:19:41 +0100 Subject: [PATCH] feat: allow any type of processor classes (#50) --- doc/01_Doc_Types_and_Available_Processors.md | 2 ++ public/js/settings.js | 2 +- src/Processor.php | 25 +++++++++++++++----- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/doc/01_Doc_Types_and_Available_Processors.md b/doc/01_Doc_Types_and_Available_Processors.md index ef56bb6..acfcb70 100644 --- a/doc/01_Doc_Types_and_Available_Processors.md +++ b/doc/01_Doc_Types_and_Available_Processors.md @@ -16,3 +16,5 @@ This bundle introduces 2 new document types: | [PDF Reactor](https://www.pdfreactor.com/) | A REST/SOAP solution, please visit the official website for further information | > For details on how to install and configure these processors, please see [Additional Tools Installation](https://pimcore.com/docs/platform/Pimcore/Installation_and_Upgrade/System_Setup_and_Hosting/Additional_Tools_Installation) page in the Core. + +You can also add your own Processors as long as they extend the abstract Pimcore\Bundle\WebToPrintBundle\Processor class. Set the full class name in the web2print settings, for example "App\Web2Print\Processor\WkHtmlToPdf". \ No newline at end of file diff --git a/public/js/settings.js b/public/js/settings.js index e735042..1f72883 100644 --- a/public/js/settings.js +++ b/public/js/settings.js @@ -328,7 +328,7 @@ pimcore.bundle.web2print.settings = Class.create({ fieldLabel: t("web2print_tool"), xtype: "combo", width: 600, - editable: false, + editable: true, name: "generalTool", value: this.getValue("generalTool"), store: [ diff --git a/src/Processor.php b/src/Processor.php index cf2c5b2..7ac2915 100644 --- a/src/Processor.php +++ b/src/Processor.php @@ -40,12 +40,25 @@ public static function getInstance(): PdfReactor|Gotenberg|Chromium|Processor { $config = Config::getWeb2PrintConfig(); - return match ($config['generalTool']) { - 'pdfreactor' => new PdfReactor(), - 'chromium' => new Chromium(), - 'gotenberg' => new Gotenberg(), - default => throw new \Exception('Invalid Configuration - ' . $config['generalTool']) - }; + if($config['generalTool'] == 'pdfreactor'){ + return new PdfReactor(); + } + elseif($config['generalTool'] == 'chromium'){ + return new Chromium(); + } + elseif($config['generalTool'] == 'gotenberg'){ + return new Gotenberg(); + } + else{ + if(class_exists($config['generalTool'])){ + $generalToolClass = new $config['generalTool'](); + if($generalToolClass instanceof Processor){ + return $generalToolClass; + } + } + } + + throw new \Exception('Invalid Configuration - ' . $config['generalTool']); } /**