diff --git a/Build/phpstan/Core12/phpstan-baseline.neon b/Build/phpstan/Core12/phpstan-baseline.neon index c65db8c2..5e2a265a 100644 --- a/Build/phpstan/Core12/phpstan-baseline.neon +++ b/Build/phpstan/Core12/phpstan-baseline.neon @@ -60,11 +60,6 @@ parameters: count: 1 path: ../../../Classes/Hooks/ButtonBarHook.php - - - message: "#^There is no aspect \"frontend\\.preview\" configured so we can't figure out the exact type to return when calling TYPO3\\\\CMS\\\\Core\\\\Context\\\\Context\\:\\:getPropertyFromAspect$#" - count: 1 - path: ../../../Classes/Hooks/DeeplPreviewFlagGeneratePageHook.php - - message: "#^Parameter \\#1 \\$uid of method WebVision\\\\Deepltranslate\\\\Core\\\\Domain\\\\Repository\\\\GlossaryEntryRepository\\:\\:findEntryByUid\\(\\) expects int, int\\|string given\\.$#" count: 1 diff --git a/Build/phpstan/Core12/phpstan.neon b/Build/phpstan/Core12/phpstan.neon index 316d163a..85b91ad8 100644 --- a/Build/phpstan/Core12/phpstan.neon +++ b/Build/phpstan/Core12/phpstan.neon @@ -16,3 +16,7 @@ parameters: - ../../../.Build/* - ../../../Tests/Functional/Updates/Fixtures/Extension/test_extension/ext_emconf.php - ../../../Tests/Functional/Fixtures/Extensions/test_services_override/ext_emconf.php + + typo3: + contextApiGetAspectMapping: + 'frontend.preview': TYPO3\CMS\Frontend\Aspect\PreviewAspect diff --git a/Classes/Event/Listener/RenderTranslatedFlagInFrontendPreviewMode.php b/Classes/Event/Listener/RenderTranslatedFlagInFrontendPreviewMode.php new file mode 100644 index 00000000..15879dfb --- /dev/null +++ b/Classes/Event/Listener/RenderTranslatedFlagInFrontendPreviewMode.php @@ -0,0 +1,77 @@ +getTypoScriptFrontendController($event); + $context = $controller->getContext(); + if ( + !$this->isInPreviewMode($context) + || $this->processWorkspacePreview($context) + || ($controller->config['config']['disablePreviewNotification'] ?? false) + || ( + isset($controller->page['tx_wvdeepltranslate_translated_time']) + && $controller->page['tx_wvdeepltranslate_translated_time'] === 0 + ) + ) { + // Preview flag must not be inserted. Return early. + return; + } + + $messagePreviewLabel = ($controller->config['config']['deepl_message_preview'] ?? '') + ?: 'Translated with DeepL'; + + $styles = []; + $styles[] = 'position: fixed'; + $styles[] = 'top: 65px'; + $styles[] = 'right: 15px'; + $styles[] = 'padding: 8px 18px'; + $styles[] = 'background: #006494'; + $styles[] = 'border: 1px solid #006494'; + $styles[] = 'font-family: sans-serif'; + $styles[] = 'font-size: 14px'; + $styles[] = 'font-weight: bold'; + $styles[] = 'color: #fff'; + $styles[] = 'z-index: 20000'; + $styles[] = 'user-select: none'; + $styles[] = 'pointer-events: none'; + $styles[] = 'text-align: center'; + $styles[] = 'border-radius: 2px'; + $message = '