From 1dc3a74fcfe52809c1fe558d9f163c4a93758808 Mon Sep 17 00:00:00 2001 From: Igor Manjencic Date: Wed, 13 Dec 2023 16:43:06 +0100 Subject: [PATCH] feat(ZMS-1711): fix template --- .../src/Zmsentities/Helper/Messaging.php | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/zmsentities/src/Zmsentities/Helper/Messaging.php b/zmsentities/src/Zmsentities/Helper/Messaging.php index 478d0eb87..e851399c0 100644 --- a/zmsentities/src/Zmsentities/Helper/Messaging.php +++ b/zmsentities/src/Zmsentities/Helper/Messaging.php @@ -198,8 +198,8 @@ protected static function getTemplate($type, $status, ?Process $process = null) if ($process) { $provider = $process->getCurrentScope()->getProvider(); $providerName = $provider->getDisplayName() ?? $provider->getName(); - $providerName = str_replace(['(', ')', '/'], '', $providerName); - $providerTemplate = 'custom/' . $type . '/' . $status . '/' . $providerName . '.twig'; + $providerTemplateName = self::getProviderTemplateName($providerName); + $providerTemplate = 'custom/' . $type . '/' . $status . '/' . $providerTemplateName . '.twig'; if (file_exists(TemplateFinder::getTemplatePath() . '/messaging/' . $providerTemplate)) { return $providerTemplate; @@ -215,6 +215,26 @@ protected static function getTemplate($type, $status, ?Process $process = null) return $template; } + private static function getProviderTemplateName($providerName) + { + if (strpos($providerName, '(')) { + $providerName = substr($providerName, 0, strpos($providerName, '(')); + } + $divider = '-'; + $providerTemplate = preg_replace('~[^\pL\d]+~u', $divider, $providerName); + $providerTemplate = iconv('utf-8', 'us-ascii//TRANSLIT', $providerTemplate); + $providerTemplate = preg_replace('~[^-\w]+~', '', $providerTemplate); + $providerTemplate = trim($providerTemplate, $divider); + $providerTemplate = preg_replace('~-+~', $divider, $providerTemplate); + $providerTemplate = strtolower($providerTemplate); + + if (empty($providerTemplate)) { + return 'none'; + } + + return $providerTemplate; + } + public static function getMailSubject( Process $process, Config $config,