From 785637254b0bd5baf40ff9df710135862ef1b10e Mon Sep 17 00:00:00 2001 From: MaxBuhe01 Date: Fri, 6 Sep 2024 18:24:42 +0200 Subject: [PATCH] [Fixed] no img leads to an error [Added] metadata setting for alternative PDF-Logo filename; translations [Changed] img-handling in documentsGeneric and header.html.twig I didn't check for smarty yet! --- .../AbstractClasses/pdfdocumentsGeneric.php | 30 ++++++++++++++++++- .../admin_smarty/de/pdfdocuments_lang.php | 6 +++- .../admin_smarty/en/pdfdocuments_lang.php | 6 +++- .../views/admin_twig/de/pdfdocuments_lang.php | 12 ++++++-- .../views/admin_twig/en/pdfdocuments_lang.php | 6 +++- metadata.php | 6 ++++ .../twig/documents/inc/page/header.html.twig | 5 +++- 7 files changed, 63 insertions(+), 8 deletions(-) diff --git a/Application/Model/AbstractClasses/pdfdocumentsGeneric.php b/Application/Model/AbstractClasses/pdfdocumentsGeneric.php index cbcbe6f..15270eb 100644 --- a/Application/Model/AbstractClasses/pdfdocumentsGeneric.php +++ b/Application/Model/AbstractClasses/pdfdocumentsGeneric.php @@ -12,13 +12,16 @@ namespace D3\PdfDocuments\Application\Model\AbstractClasses; use Assert\InvalidArgumentException; use D3\ModCfg\Application\Model\d3filesystem; +use D3\PdfDocuments\Application\Model\Constants; use D3\PdfDocuments\Application\Model\Exceptions\pdfGeneratorExceptionAbstract; use D3\PdfDocuments\Application\Model\Interfaces\pdfdocumentsGenericInterface as genericInterface; use OxidEsales\Eshop\Core\Base; use OxidEsales\Eshop\Core\Exception\StandardException; use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\UtilsView; +use OxidEsales\EshopCommunity\Core\Di\ContainerFacade; use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; +use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface; use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateEngineInterface; use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRenderer; use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererBridgeInterface; @@ -182,12 +185,37 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface unset($iSelLang); $this->oTemplateEngine->addGlobal('config', Registry::getConfig()); + $this->oTemplateEngine->addGlobal('sAlternativePdfLogo', $this->getAlternativePdfLogoFileName()); $this->oTemplateEngine->addGlobal('oViewConf', Registry::getConfig()->getActiveView()->getViewConfig()); $this->oTemplateEngine->addGlobal('shop', Registry::getConfig()->getActiveShop()); $this->oTemplateEngine->addGlobal('lang', Registry::getLang()); $this->oTemplateEngine->addGlobal('document', $this); } - + + /** + * @return string + */ + public function getAlternativePdfLogoFileName() :string + { + $sStandardLogoFile = 'pdf_logo.jpg'; + $oViewConf = Registry::getConfig()->getActiveView()->getViewConfig(); + $moduleSettingService = ContainerFacade::get(ModuleSettingServiceInterface::class); + $sAlternativePdfLogoName = $moduleSettingService->getString(Constants::OXID_MODULE_ID."_sAlternativePdfLogoName", Constants::OXID_MODULE_ID); + + $sAlternativePdfLogoName = trim($sAlternativePdfLogoName) ?: $sStandardLogoFile; + + $bAlternativeFileExists = file_exists(Registry::getConfig()->getImagePath($sAlternativePdfLogoName)); + $bFileExists = file_exists(Registry::getConfig()->getImagePath($sStandardLogoFile)); + + return $bAlternativeFileExists + ? $oViewConf->getImageUrl($sAlternativePdfLogoName, true) + : ( + $bFileExists + ? $oViewConf->getImageUrl($sStandardLogoFile, true) + : "" + ); + } + /** * @param int $iSelLang * diff --git a/Application/views/admin_smarty/de/pdfdocuments_lang.php b/Application/views/admin_smarty/de/pdfdocuments_lang.php index 7348b26..272abd5 100644 --- a/Application/views/admin_smarty/de/pdfdocuments_lang.php +++ b/Application/views/admin_smarty/de/pdfdocuments_lang.php @@ -13,7 +13,11 @@ $aLang = array( 'charset' => 'utf-8', 'SHOP_MODULE_GROUP_d3PdfDocumentsmain' => 'Grundeinstellungen', - 'SHOP_MODULE_d3PdfDocumentsbDev' => 'Entwicklermodus', + 'SHOP_MODULE_'. Constants::OXID_MODULE_ID.'bDev' => 'Entwicklermodus', + 'SHOP_MODULE_'. Constants::OXID_MODULE_ID.'_sAlternativePdfLogoName' => 'Alternativer PDF-Logo Name

+ Ohne Angabe ( leer ) wird automatisch folgender Datei-Name gewählt: pdf_logo.jpg
+ Diese Datei muss sich im source/out/THEME/img/ Ordner befinden.

+ Notfalls wird kein Bild eingefügt!', 'D3_PDFDOCUMENTS' => 'PDF-Dokumente', 'D3_PDFDOCUMENTS_INVOICE' => 'Rechnung', diff --git a/Application/views/admin_smarty/en/pdfdocuments_lang.php b/Application/views/admin_smarty/en/pdfdocuments_lang.php index 52888d0..3d5cd76 100644 --- a/Application/views/admin_smarty/en/pdfdocuments_lang.php +++ b/Application/views/admin_smarty/en/pdfdocuments_lang.php @@ -13,7 +13,11 @@ $aLang = array( 'charset' => 'utf-8', 'SHOP_MODULE_GROUP_d3PdfDocumentsmain' => 'Basic settings', - 'SHOP_MODULE_d3PdfDocumentsbDev' => 'Developer mode', + 'SHOP_MODULE_'. Constants::OXID_MODULE_ID.'bDev' => 'Developer mode', + 'SHOP_MODULE_'. Constants::OXID_MODULE_ID.'_sAlternativePdfLogoName' => 'Alternative PDF Logo Name

+ Without specification (empty) the following file name will be automatically selected: pdf_logo.jpg
+ This file must be located in the source/out/THEME/img/ folder.

+ If necessary, no image will be inserted!', 'D3_PDFDOCUMENTS' => 'PDF Documents', 'D3_PDFDOCUMENTS_INVOICE' => 'Invoice', diff --git a/Application/views/admin_twig/de/pdfdocuments_lang.php b/Application/views/admin_twig/de/pdfdocuments_lang.php index 7348b26..9a3d3d2 100644 --- a/Application/views/admin_twig/de/pdfdocuments_lang.php +++ b/Application/views/admin_twig/de/pdfdocuments_lang.php @@ -7,13 +7,19 @@ * @author D3 Data Development - Daniel Seifert * @link http://www.oxidmodule.com */ - -$sLangName = "Deutsch"; + + use D3\PdfDocuments\Application\Model\Constants; + + $sLangName = "Deutsch"; $aLang = array( 'charset' => 'utf-8', 'SHOP_MODULE_GROUP_d3PdfDocumentsmain' => 'Grundeinstellungen', - 'SHOP_MODULE_d3PdfDocumentsbDev' => 'Entwicklermodus', + 'SHOP_MODULE_'. Constants::OXID_MODULE_ID.'bDev' => 'Entwicklermodus', + 'SHOP_MODULE_'. Constants::OXID_MODULE_ID.'_sAlternativePdfLogoName' => 'Alternativer PDF-Logo Name

+ Ohne Angabe ( leer ) wird automatisch folgender Datei-Name gewählt: pdf_logo.jpg
+ Diese Datei muss sich im source/out/THEME/img/ Ordner befinden.

+ Notfalls wird kein Bild eingefügt!', 'D3_PDFDOCUMENTS' => 'PDF-Dokumente', 'D3_PDFDOCUMENTS_INVOICE' => 'Rechnung', diff --git a/Application/views/admin_twig/en/pdfdocuments_lang.php b/Application/views/admin_twig/en/pdfdocuments_lang.php index 52888d0..3d5cd76 100644 --- a/Application/views/admin_twig/en/pdfdocuments_lang.php +++ b/Application/views/admin_twig/en/pdfdocuments_lang.php @@ -13,7 +13,11 @@ $aLang = array( 'charset' => 'utf-8', 'SHOP_MODULE_GROUP_d3PdfDocumentsmain' => 'Basic settings', - 'SHOP_MODULE_d3PdfDocumentsbDev' => 'Developer mode', + 'SHOP_MODULE_'. Constants::OXID_MODULE_ID.'bDev' => 'Developer mode', + 'SHOP_MODULE_'. Constants::OXID_MODULE_ID.'_sAlternativePdfLogoName' => 'Alternative PDF Logo Name

+ Without specification (empty) the following file name will be automatically selected: pdf_logo.jpg
+ This file must be located in the source/out/THEME/img/ folder.

+ If necessary, no image will be inserted!', 'D3_PDFDOCUMENTS' => 'PDF Documents', 'D3_PDFDOCUMENTS_INVOICE' => 'Invoice', diff --git a/metadata.php b/metadata.php index 169cac9..c6c34b2 100644 --- a/metadata.php +++ b/metadata.php @@ -92,6 +92,12 @@ $aModule = [ 'name' => Constants::OXID_MODULE_ID.'bDev', 'type' => 'bool', 'value' => false + ], + [ + 'group' => Constants::OXID_MODULE_ID.'main', + 'name' => Constants::OXID_MODULE_ID.'_sAlternativePdfLogoName', + 'type' => 'str', + 'value' => '' ] ] ]; diff --git a/views/twig/documents/inc/page/header.html.twig b/views/twig/documents/inc/page/header.html.twig index 3d76c6e..04018bb 100644 --- a/views/twig/documents/inc/page/header.html.twig +++ b/views/twig/documents/inc/page/header.html.twig @@ -1,4 +1,5 @@ {% set showLogo = showLogo|default(1) %} +{% set sPdfLogo = sAlternativePdfLogo %} {% block pdfHeader %}
@@ -6,7 +7,9 @@ {# pdf logo is available only in non admin theme #} {% set isAdmin = oViewConf.isAdmin() %} {{ oViewConf.setAdminMode(false) }} - + {% if sPdfLogo %} + + {% endif %} {{ oViewConf.setAdminMode(isAdmin) }} {% endif %}