Skip to content

Commit

Permalink
Merge pull request #68 from it-at-m/feature-1711-custom-mail-templates
Browse files Browse the repository at this point in the history
feat(ZMS-1711): fix template
  • Loading branch information
manjencic authored Dec 13, 2023
2 parents cc82254 + 1dc3a74 commit 618cdbe
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions zmsentities/src/Zmsentities/Helper/Messaging.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down

0 comments on commit 618cdbe

Please sign in to comment.