From a78d7cb606e7444d84bcb787e071951888dfd762 Mon Sep 17 00:00:00 2001 From: fritzmg Date: Thu, 23 May 2024 22:56:58 +0100 Subject: [PATCH] add German translation and use token factory again --- contao/languages/de/nc_tokens.xlf | 8 ++++++-- contao/languages/en/nc_tokens.xlf | 8 ++++---- src/EventListener/AdminEmailTokenListener.php | 15 ++++++++++----- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/contao/languages/de/nc_tokens.xlf b/contao/languages/de/nc_tokens.xlf index fcf9f875..42a30bfb 100644 --- a/contao/languages/de/nc_tokens.xlf +++ b/contao/languages/de/nc_tokens.xlf @@ -3,8 +3,12 @@ - E-mail address of administrator of the current page (website root settings). - E-Mail-Adresse des Administrators der aktuellen Seite (Einstellungen der Rootseite). + E-mail address of the administrator of the current page (system config or website root settings). + E-Mail-Adresse des Administrators der aktuellen Seite (Systemeinstellungen oder Einstellungen der Rootseite). + + + Friendly name for the e-mail address of the administrator of the current page (system config or website root settings). + Anzeigename für die E-Mail-Adresse des Administrators der aktuellen Seite (Systemeinstellungen oder Einstellungen der Rootseite). All the form fields. diff --git a/contao/languages/en/nc_tokens.xlf b/contao/languages/en/nc_tokens.xlf index d6162556..2fccbe5a 100644 --- a/contao/languages/en/nc_tokens.xlf +++ b/contao/languages/en/nc_tokens.xlf @@ -2,14 +2,14 @@ - - Friendly name for the e-mail address of the administrator of the current page (system config or website root settings). - Friendly name for the e-mail address of the administrator of the current page (system config or website root settings). - E-mail address of the administrator of the current page (system config or website root settings). E-mail address of the administrator of the current page (system config or website root settings). + + Friendly name for the e-mail address of the administrator of the current page (system config or website root settings). + Friendly name for the e-mail address of the administrator of the current page (system config or website root settings). + All the form fields. All the form fields. diff --git a/src/EventListener/AdminEmailTokenListener.php b/src/EventListener/AdminEmailTokenListener.php index 73c630ad..b03671c9 100644 --- a/src/EventListener/AdminEmailTokenListener.php +++ b/src/EventListener/AdminEmailTokenListener.php @@ -15,7 +15,7 @@ use Terminal42\NotificationCenterBundle\Parcel\Stamp\TokenCollectionStamp; use Terminal42\NotificationCenterBundle\Token\Definition\EmailTokenDefinition; use Terminal42\NotificationCenterBundle\Token\Definition\Factory\TokenDefinitionFactoryInterface; -use Terminal42\NotificationCenterBundle\Token\Token; +use Terminal42\NotificationCenterBundle\Token\Definition\TokenDefinitionInterface; class AdminEmailTokenListener { @@ -30,8 +30,8 @@ public function __construct( public function onGetTokenDefinitions(GetTokenDefinitionsForNotificationTypeEvent $event): void { $event - ->addTokenDefinition($this->tokenDefinitionFactory->create(EmailTokenDefinition::class, 'admin_name', 'admin_name')) - ->addTokenDefinition($this->tokenDefinitionFactory->create(EmailTokenDefinition::class, 'admin_email', 'admin_email')) + ->addTokenDefinition($this->getTokenDefinition('admin_email')) + ->addTokenDefinition($this->getTokenDefinition('admin_name')) ; } @@ -53,8 +53,8 @@ public function onCreateParcel(CreateParcelEvent $event): void } $event->getParcel()->getStamp(TokenCollectionStamp::class)->tokenCollection - ->addToken(new Token('admin_name', $email[0], $email[0])) - ->addToken(new Token('admin_email', $email[1], $email[1])) + ->addToken($this->getTokenDefinition('admin_email')->createToken('admin_email', $email[1])) + ->addToken($this->getTokenDefinition('admin_name')->createToken('admin_name', $email[0])) ; } @@ -82,6 +82,11 @@ private function getEmailFromConfig(): array|null return $email ? $this->parseFriendlyEmail($email) : null; } + private function getTokenDefinition(string $token): TokenDefinitionInterface + { + return $this->tokenDefinitionFactory->create(EmailTokenDefinition::class, $token, $token); + } + private function parseFriendlyEmail(string $email): array { return $this->contaoFramework->getAdapter(StringUtil::class)->splitFriendlyEmail($email);