From 2940bab900d0629fbea5598d805dfa8fa845c30b Mon Sep 17 00:00:00 2001 From: pKallert <91674611+pKallert@users.noreply.github.com> Date: Wed, 11 Oct 2023 11:59:08 +0200 Subject: [PATCH 1/3] Feature: Refactor Login translations --- .../Classes/Controller/LoginController.php | 61 ++++++------------- .../Classes/Controller/TranslationTrait.php | 42 +++++++++++++ 2 files changed, 62 insertions(+), 41 deletions(-) create mode 100644 Neos.Neos/Classes/Controller/TranslationTrait.php diff --git a/Neos.Neos/Classes/Controller/LoginController.php b/Neos.Neos/Classes/Controller/LoginController.php index 7493b1b4510..6ceb973f5e6 100644 --- a/Neos.Neos/Classes/Controller/LoginController.php +++ b/Neos.Neos/Classes/Controller/LoginController.php @@ -31,7 +31,7 @@ use Neos\Flow\Session\SessionInterface; use Neos\Flow\Session\SessionManagerInterface; use Neos\Fusion\View\FusionView; -use Neos\Neos\Controller\Module\ModuleTranslationTrait; +use Neos\Neos\Controller\TranslationTrait; use Neos\Neos\Domain\Repository\DomainRepository; use Neos\Neos\Domain\Repository\SiteRepository; use Neos\Neos\Service\BackendRedirectionService; @@ -41,48 +41,30 @@ */ class LoginController extends AbstractAuthenticationController { - use ModuleTranslationTrait; + use TranslationTrait; /** * @var string */ protected $defaultViewObjectName = FusionView::class; - /** - * @Flow\Inject - * @var SessionInterface - */ - protected $session; + #[Flow\Inject] + protected SessionInterface $session; - /** - * @Flow\Inject - * @var SessionManagerInterface - */ - protected $sessionManager; + #[Flow\Inject] + protected SessionManagerInterface $sessionManager; - /** - * @Flow\Inject - * @var BackendRedirectionService - */ - protected $backendRedirectionService; + #[Flow\Inject] + protected BackendRedirectionService $backendRedirectionService; - /** - * @Flow\Inject - * @var DomainRepository - */ - protected $domainRepository; + #[Flow\Inject] + protected DomainRepository $domainRepository; - /** - * @Flow\Inject - * @var SiteRepository - */ - protected $siteRepository; + #[Flow\Inject] + protected SiteRepository $siteRepository; - /** - * @Flow\Inject - * @var StringFrontend - */ - protected $loginTokenCache; + #[Flow\Inject] + protected StringFrontend $loginTokenCache; /** * @Flow\InjectConfiguration(package="Neos.Flow", path="session.name") @@ -90,11 +72,8 @@ class LoginController extends AbstractAuthenticationController */ protected $sessionName; - /** - * @Flow\Inject - * @var FlashMessageService - */ - protected $flashMessageService; + #[Flow\Inject] + protected FlashMessageService $flashMessageService; /** * @var array @@ -217,8 +196,8 @@ protected function onAuthenticationFailure(AuthenticationRequiredException $exce $this->view->assign('value', ['success' => false]); } else { $this->addFlashMessage( - $this->getModuleLabel('login.wrongCredentials.body'), - $this->getModuleLabel('login.wrongCredentials.title'), + $this->getLabel('login.wrongCredentials.body'), + $this->getLabel('login.wrongCredentials.title'), Message::SEVERITY_ERROR, [], $exception === null ? 1347016771 : $exception->getCode() @@ -285,8 +264,8 @@ public function logoutAction() $this->redirectToUri($possibleRedirectionUri); } $this->addFlashMessage( - $this->getModuleLabel('login.loggedOut.body'), - $this->getModuleLabel('login.loggedOut.title'), + $this->getLabel('login.loggedOut.body'), + $this->getLabel('login.loggedOut.title'), Message::SEVERITY_NOTICE, [], 1318421560 diff --git a/Neos.Neos/Classes/Controller/TranslationTrait.php b/Neos.Neos/Classes/Controller/TranslationTrait.php new file mode 100644 index 00000000000..2610442445d --- /dev/null +++ b/Neos.Neos/Classes/Controller/TranslationTrait.php @@ -0,0 +1,42 @@ + $arguments + */ + public function getLabel(string $id, array $arguments = []): string + { + return $this->translator->translateById( + $id, + $arguments, + null, + null, + 'Main', + 'Neos.Neos' + ) ?: $id; + } +} From abf90448c5f54351c9acb150228faefeed375f27 Mon Sep 17 00:00:00 2001 From: pKallert <91674611+pKallert@users.noreply.github.com> Date: Thu, 12 Oct 2023 08:29:18 +0200 Subject: [PATCH 2/3] Feature: remove unused code --- Neos.Neos/Classes/Controller/LoginController.php | 8 ++++---- .../Resources/Private/Fusion/Backend/Views/Login.fusion | 4 ++-- Neos.Neos/Resources/Private/Translations/en/Main.xlf | 5 ----- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/Neos.Neos/Classes/Controller/LoginController.php b/Neos.Neos/Classes/Controller/LoginController.php index 6ceb973f5e6..acbddbc7cf2 100644 --- a/Neos.Neos/Classes/Controller/LoginController.php +++ b/Neos.Neos/Classes/Controller/LoginController.php @@ -190,7 +190,7 @@ public function tokenLoginAction(string $token): void * @param AuthenticationRequiredException $exception The exception thrown while the authentication process * @return void */ - protected function onAuthenticationFailure(AuthenticationRequiredException $exception = null) + protected function onAuthenticationFailure(AuthenticationRequiredException $exception = null): void { if ($this->view instanceof JsonView) { $this->view->assign('value', ['success' => false]); @@ -216,7 +216,7 @@ protected function onAuthenticationFailure(AuthenticationRequiredException $exce * @throws StopActionException * @throws \Neos\Flow\Mvc\Exception\NoSuchArgumentException */ - protected function onAuthenticationSuccess(ActionRequest $originalRequest = null) + protected function onAuthenticationSuccess(ActionRequest $originalRequest = null): void { if ($this->view instanceof JsonView) { $this->view->assign( @@ -251,7 +251,7 @@ protected function onAuthenticationSuccess(ActionRequest $originalRequest = null * * @return void */ - public function logoutAction() + public function logoutAction(): void { $possibleRedirectionUri = $this->backendRedirectionService->getAfterLogoutRedirectionUri($this->request); parent::logoutAction(); @@ -281,7 +281,7 @@ public function logoutAction() * @phpstan-ignore-next-line Flow does not properly declare its types here * @return false */ - protected function getErrorFlashMessage() + protected function getErrorFlashMessage(): bool { return false; } diff --git a/Neos.Neos/Resources/Private/Fusion/Backend/Views/Login.fusion b/Neos.Neos/Resources/Private/Fusion/Backend/Views/Login.fusion index 91a8b7cc997..7d9fc5288d7 100644 --- a/Neos.Neos/Resources/Private/Fusion/Backend/Views/Login.fusion +++ b/Neos.Neos/Resources/Private/Fusion/Backend/Views/Login.fusion @@ -152,7 +152,7 @@ prototype(Neos.Neos:Component.Login.Form) < prototype(Neos.Fusion:Component) {
@@ -160,4 +160,4 @@ prototype(Neos.Neos:Component.Login.Form) < prototype(Neos.Fusion:Component) { ` -} \ No newline at end of file +} diff --git a/Neos.Neos/Resources/Private/Translations/en/Main.xlf b/Neos.Neos/Resources/Private/Translations/en/Main.xlf index 8bc8cfbd1d4..f05e47f60fd 100644 --- a/Neos.Neos/Resources/Private/Translations/en/Main.xlf +++ b/Neos.Neos/Resources/Private/Translations/en/Main.xlf @@ -729,11 +729,6 @@ Node Tree loading error. - - - The entered username or password was wrong - - "{nodeTypeName}" on page "{pageLabel}" From 2002bd942ab9d4ecde0d8dce363760f700ffbf05 Mon Sep 17 00:00:00 2001 From: pKallert <91674611+pKallert@users.noreply.github.com> Date: Thu, 12 Oct 2023 10:25:11 +0200 Subject: [PATCH 3/3] Fix: Translation Trait namespace --- Neos.Neos/Classes/Controller/LoginController.php | 11 +++++++---- Neos.Neos/Classes/Controller/TranslationTrait.php | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Neos.Neos/Classes/Controller/LoginController.php b/Neos.Neos/Classes/Controller/LoginController.php index acbddbc7cf2..43fed8f5ff2 100644 --- a/Neos.Neos/Classes/Controller/LoginController.php +++ b/Neos.Neos/Classes/Controller/LoginController.php @@ -64,7 +64,13 @@ class LoginController extends AbstractAuthenticationController protected SiteRepository $siteRepository; #[Flow\Inject] - protected StringFrontend $loginTokenCache; + protected FlashMessageService $flashMessageService; + + /** + * @Flow\Inject + * @var StringFrontend + */ + protected $loginTokenCache; /** * @Flow\InjectConfiguration(package="Neos.Flow", path="session.name") @@ -72,9 +78,6 @@ class LoginController extends AbstractAuthenticationController */ protected $sessionName; - #[Flow\Inject] - protected FlashMessageService $flashMessageService; - /** * @var array */ diff --git a/Neos.Neos/Classes/Controller/TranslationTrait.php b/Neos.Neos/Classes/Controller/TranslationTrait.php index 2610442445d..d0b048ace0d 100644 --- a/Neos.Neos/Classes/Controller/TranslationTrait.php +++ b/Neos.Neos/Classes/Controller/TranslationTrait.php @@ -12,7 +12,7 @@ declare(strict_types=1); -namespace Neos\Neos\Controller\Module; +namespace Neos\Neos\Controller; use Neos\Flow\Annotations as Flow; use Neos\Flow\I18n\Translator;