From a8614240d5490a47e857f57d29c2ba92fee5b4d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BCrk?= Date: Sat, 14 Dec 2024 22:50:37 +0100 Subject: [PATCH] [!!!][TASK] Remove obsolete `DeeplPreviewFlagGeneratePageHook` Since TYPO3 v12 `contentPostProc-all` hook is not called and replaced with PSR-14 event `AfterCacheableContentIsGeneratedEvent`, which has been respected with * #397 * #398 TYPO3 v11 support has been removed and this change cleansup introduced dual version code with upporting the bugfix as a housekeeping change. Further, the now obsolete hook is completly removed. Related: #397 Related: #398 --- ...derTranslatedFlagInFrontendPreviewMode.php | 4 +- .../DeeplPreviewFlagGeneratePageHook.php | 59 ------------------- Configuration/Services.php | 22 +++---- ext_localconf.php | 6 -- 4 files changed, 9 insertions(+), 82 deletions(-) delete mode 100644 Classes/Hooks/DeeplPreviewFlagGeneratePageHook.php diff --git a/Classes/Event/Listener/RenderTranslatedFlagInFrontendPreviewMode.php b/Classes/Event/Listener/RenderTranslatedFlagInFrontendPreviewMode.php index eaffb0b0..d91f48c5 100644 --- a/Classes/Event/Listener/RenderTranslatedFlagInFrontendPreviewMode.php +++ b/Classes/Event/Listener/RenderTranslatedFlagInFrontendPreviewMode.php @@ -7,13 +7,11 @@ use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; use TYPO3\CMS\Frontend\Event\AfterCacheableContentIsGeneratedEvent; -use WebVision\Deepltranslate\Core\Hooks\DeeplPreviewFlagGeneratePageHook; /** * Event listener to render the frontend preview flag information. * - * TYPO3 v12+ only and this is the counter-part of the {@see DeeplPreviewFlagGeneratePageHook} for older TYPO3 versions. - * https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/12.0/Breaking-97862-HooksRelatedToGeneratingPageContentRemoved.html + * @internal for `deepltranslate-core` internal usage and not part of public API. */ final class RenderTranslatedFlagInFrontendPreviewMode { diff --git a/Classes/Hooks/DeeplPreviewFlagGeneratePageHook.php b/Classes/Hooks/DeeplPreviewFlagGeneratePageHook.php deleted file mode 100644 index 90b73233..00000000 --- a/Classes/Hooks/DeeplPreviewFlagGeneratePageHook.php +++ /dev/null @@ -1,59 +0,0 @@ -getContext()->hasAspect('frontend.preview') - && $controller->getContext()->getPropertyFromAspect('frontend.preview', 'isPreview'); - if ( - !$isInPreviewMode - || $controller->getContext()->getPropertyFromAspect('workspace', 'isOffline', false) - || ($controller->config['config']['disablePreviewNotification'] ?? false) - || ( - isset($controller->page['tx_wvdeepltranslate_translated_time']) - && $controller->page['tx_wvdeepltranslate_translated_time'] === 0 - ) - ) { - return; - } - - $messagePreviewLabel = $controller->config['config']['deepl_message_preview'] ?? ''; - if ($messagePreviewLabel === '') { - $messagePreviewLabel = '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 = '
' . htmlspecialchars($messagePreviewLabel) . '
'; - - $controller->content = str_ireplace('', $message . '', $controller->content); - } -} diff --git a/Configuration/Services.php b/Configuration/Services.php index d122d354..1ce04c01 100644 --- a/Configuration/Services.php +++ b/Configuration/Services.php @@ -9,7 +9,6 @@ use TYPO3\CMS\Core\Cache\CacheManager; use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface; use TYPO3\CMS\Core\DependencyInjection\SingletonPass; -use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Dashboard\WidgetRegistry; use WebVision\Deepltranslate\Core\Client; use WebVision\Deepltranslate\Core\ClientInterface; @@ -35,8 +34,6 @@ use WebVision\Deepltranslate\Core\Widgets\UsageWidget; return function (ContainerConfigurator $containerConfigurator, ContainerBuilder $containerBuilder) { - $typo3version = new Typo3Version(); - $services = $containerConfigurator ->services(); $services->defaults() @@ -162,17 +159,14 @@ ] ); - if ((new Typo3Version())->getMajorVersion() >= 12) { - // @todo Unnest this in next major when TYPO3 v11 support has been removed. - $services - ->set(RenderTranslatedFlagInFrontendPreviewMode::class) - ->tag( - 'event.listener', - [ - 'identifier' => 'deepltranslate-core/render-translated-flag-in-frontend-preview-mode', - ] - ); - } + $services + ->set(RenderTranslatedFlagInFrontendPreviewMode::class) + ->tag( + 'event.listener', + [ + 'identifier' => 'deepltranslate-core/render-translated-flag-in-frontend-preview-mode', + ] + ); /** * Check if WidgetRegistry is defined, which means that EXT:dashboard is available. diff --git a/ext_localconf.php b/ext_localconf.php index 76dff73f..5ca4866d 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -26,12 +26,6 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList']['deepl'] = \WebVision\Deepltranslate\Core\Hooks\TCEmainHook::class; - if ($typo3version->getMajorVersion() < 12) { - // @todo Remove when TYPO3 v11 support is removed. - $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['contentPostProc-all']['deepl-1675946132'] = - \WebVision\WvDeepltranslate\Hooks\DeeplPreviewFlagGeneratePageHook::class . '->renderDeeplPreviewFlag'; - } - //xclass localizationcontroller for localizeRecords() and process() action $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\TYPO3\CMS\Backend\Controller\Page\LocalizationController::class] = [ 'className' => \WebVision\Deepltranslate\Core\Override\LocalizationController::class,