diff --git a/Build/phpstan/Core12/phpstan-baseline.neon b/Build/phpstan/Core12/phpstan-baseline.neon index 1a1104fa..fc273985 100644 --- a/Build/phpstan/Core12/phpstan-baseline.neon +++ b/Build/phpstan/Core12/phpstan-baseline.neon @@ -94,18 +94,3 @@ parameters: message: "#^Cannot access property \\$code on DeepL\\\\Language\\|null\\.$#" count: 7 path: ../../../Tests/Functional/Services/DeeplServiceTest.php - - - - message: "#^Call to method create\\(\\) on an unknown class TYPO3\\\\CMS\\\\Core\\\\View\\\\ViewFactoryInterface\\.$#" - count: 1 - path: ../../../Tests/Functional/ViewHelpers/ExtensionActiveViewHelperTest.php - - - - message: "#^Class TYPO3\\\\CMS\\\\Core\\\\View\\\\ViewFactoryInterface not found\\.$#" - count: 1 - path: ../../../Tests/Functional/ViewHelpers/ExtensionActiveViewHelperTest.php - - - - message: "#^Instantiated class TYPO3\\\\CMS\\\\Core\\\\View\\\\ViewFactoryData not found\\.$#" - count: 1 - path: ../../../Tests/Functional/ViewHelpers/ExtensionActiveViewHelperTest.php diff --git a/Build/phpstan/Core13/phpstan-baseline.neon b/Build/phpstan/Core13/phpstan-baseline.neon index 8f5f68ba..7bcac531 100644 --- a/Build/phpstan/Core13/phpstan-baseline.neon +++ b/Build/phpstan/Core13/phpstan-baseline.neon @@ -94,8 +94,3 @@ parameters: message: "#^Cannot access property \\$code on DeepL\\\\Language\\|null\\.$#" count: 7 path: ../../../Tests/Functional/Services/DeeplServiceTest.php - - - - message: "#^Call to an undefined method TYPO3\\\\CMS\\\\Core\\\\View\\\\ViewInterface\\:\\:getRenderingContext\\(\\)\\.$#" - count: 3 - path: ../../../Tests/Functional/ViewHelpers/ExtensionActiveViewHelperTest.php diff --git a/Classes/Event/Listener/RenderPageViewLocalizationDropdownEventListener.php b/Classes/Event/Listener/RenderPageViewLocalizationDropdownEventListener.php new file mode 100644 index 00000000..c4f518ff --- /dev/null +++ b/Classes/Event/Listener/RenderPageViewLocalizationDropdownEventListener.php @@ -0,0 +1,79 @@ +getIdentifier() !== 'languageTranslationDropdown') { + return; + } + $translationPartials = $event->getLocalVariableProvider()->get('translationPartials'); + if ($translationPartials === null) { + $translationPartials = []; + } + $translationPartials[20] = 'Translation/DeeplTranslationDropdown'; + $event->getLocalVariableProvider()->add('translationPartials', $translationPartials); + + $deeplTranslateLanguages = []; + $event->getLocalVariableProvider()->add('deeplLanguages', []); + /** @var PageLayoutContext|null $context */ + $context = $event->getGlobalVariableProvider()->get('context'); + if ($context === null) { + return; + } + + foreach ($context->getSiteLanguages() as $siteLanguage) { + if ( + $siteLanguage->getLanguageId() != -1 + && $siteLanguage->getLanguageId() != 0 + ) { + if (!DeeplBackendUtility::checkCanBeTranslated( + $context->getPageId(), + $siteLanguage->getLanguageId() + ) + ) { + continue; + } + $deeplTranslateLanguages[$siteLanguage->getTitle()] = $siteLanguage->getLanguageId(); + } + } + if ($deeplTranslateLanguages === []) { + return; + } + $options = []; + foreach ($context->getNewLanguageOptions() as $key => $possibleLanguage) { + if ($key === 0) { + continue; + } + if (!array_key_exists($possibleLanguage, $deeplTranslateLanguages)) { + continue; + } + $parameters = [ + 'justLocalized' => 'pages:' . $context->getPageId() . ':' . $deeplTranslateLanguages[$possibleLanguage], + 'returnUrl' => $GLOBALS['TYPO3_REQUEST']->getAttribute('normalizedParams')->getRequestUri(), + ]; + + $redirectUrl = DeeplBackendUtility::buildBackendRoute('record_edit', $parameters); + $params = []; + $params['redirect'] = $redirectUrl; + $params['cmd']['pages'][$context->getPageId()]['deepltranslate'] = $deeplTranslateLanguages[$possibleLanguage]; + + $targetUrl = DeeplBackendUtility::buildBackendRoute('tce_db', $params); + + $options[$targetUrl] = $possibleLanguage; + } + + if ($options === []) { + return; + } + $event->getLocalVariableProvider()->add('deeplLanguages', $options); + } +} diff --git a/Classes/ViewHelpers/Be/ExtensionActiveViewHelper.php b/Classes/ViewHelpers/Be/ExtensionActiveViewHelper.php deleted file mode 100644 index 7aeef7c7..00000000 --- a/Classes/ViewHelpers/Be/ExtensionActiveViewHelper.php +++ /dev/null @@ -1,41 +0,0 @@ - - * - * - * - * - * - * - * - * - * Inline example: - * {deepl:be.extensionActive(extension: 'enable_translated_content', then: '', else: '')} - */ -final class ExtensionActiveViewHelper extends AbstractConditionViewHelper -{ - public function initializeArguments(): void - { - parent::initializeArguments(); - $this->registerArgument('extension', 'string', 'The extension to check', true); - } - - public static function verdict(array $arguments, RenderingContextInterface $renderingContext): bool - { - if (ExtensionManagementUtility::isLoaded((string)($arguments['extension'] ?? ''))) { - return true; - } - return false; - } -} diff --git a/Classes/ViewHelpers/DeeplTranslateViewHelper.php b/Classes/ViewHelpers/DeeplTranslateViewHelper.php index 94b56a66..48d8333b 100644 --- a/Classes/ViewHelpers/DeeplTranslateViewHelper.php +++ b/Classes/ViewHelpers/DeeplTranslateViewHelper.php @@ -7,8 +7,18 @@ use TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException; use TYPO3\CMS\Backend\View\PageLayoutContext; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; +use WebVision\Deepl\Base\Event\ViewHelpers\ModifyInjectVariablesViewHelperEvent; +use WebVision\Deepltranslate\Core\Event\Listener\RenderPageViewLocalizationDropdownEventListener; use WebVision\Deepltranslate\Core\Utility\DeeplBackendUtility; +/** + * @deprecated Will be removed in the next major release + * + * This viewHelper is deprecated, as the registration is now done by the deepl_base + * event and directly registered during the EventListener invocation. + * @see RenderPageViewLocalizationDropdownEventListener + * @see ModifyInjectVariablesViewHelperEvent + */ final class DeeplTranslateViewHelper extends AbstractViewHelper { @@ -28,6 +38,10 @@ public function initializeArguments(): void */ public function render(): array { + trigger_error( + 'This ViewHelper is deprecated and should no longer be used', + E_USER_DEPRECATED + ); $options = []; /** @var PageLayoutContext $context */ $context = $this->arguments['context']; diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index be70f8f6..f6dd83f1 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -67,3 +67,10 @@ services: identifier: 'deepltranslate-core/deepltranslate-core-localization-modes-process' event: WebVision\Deepl\Base\Event\LocalizationProcessPrepareDataHandlerCommandMapEvent after: 'deepl-base/process-default-typo3-localization-modes' + + WebVision\Deepltranslate\Core\Event\Listener\RenderPageViewLocalizationDropdownEventListener: + tags: + - name: 'event.listener' + identifier: 'deepltranslate-core/translation-dropdown' + event: WebVision\Deepl\Base\Event\ViewHelpers\ModifyInjectVariablesViewHelperEvent + after: 'deepl-base/default-translation' diff --git a/Resources/Private/Backend/Partials/AdditionalTranslation/DeeplDefault.html b/Resources/Private/Backend/Partials/AdditionalTranslation/DeeplDefault.html deleted file mode 100644 index 838e0521..00000000 --- a/Resources/Private/Backend/Partials/AdditionalTranslation/DeeplDefault.html +++ /dev/null @@ -1,36 +0,0 @@ - - -
-
- -
- - - -
- -
- -
-
-
-
-
-
-
- diff --git a/Resources/Private/Backend/Partials/PageLayout/LanguageColumns.html b/Resources/Private/Backend/Partials/PageLayout/LanguageColumns.html deleted file mode 100644 index a51f8963..00000000 --- a/Resources/Private/Backend/Partials/PageLayout/LanguageColumns.html +++ /dev/null @@ -1,145 +0,0 @@ - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-

{languageColumn.context.siteLanguage.title}

- - {languageColumn.context.languageMode} - -
- - {languageColumn.pageIcon -> f:format.raw()} - {languageColumn.context.localizedPageTitle -> f:format.crop(maxCharacters: maxTitleLength)} -
- -
- - - - - - - - - - - - - - - {languageColumns.{languageId}} - - - - - - - -
- {column.afterSectionMarkup} -
-
- diff --git a/Resources/Private/Backend/Partials/Translation/DeeplTranslationDropdown.html b/Resources/Private/Backend/Partials/Translation/DeeplTranslationDropdown.html new file mode 100644 index 00000000..127d88fd --- /dev/null +++ b/Resources/Private/Backend/Partials/Translation/DeeplTranslationDropdown.html @@ -0,0 +1,25 @@ + + + + +
+ +
+ +
+
+
+
+
+ diff --git a/Tests/Functional/ViewHelpers/ExtensionActiveViewHelperTest.php b/Tests/Functional/ViewHelpers/ExtensionActiveViewHelperTest.php deleted file mode 100644 index 892a75b9..00000000 --- a/Tests/Functional/ViewHelpers/ExtensionActiveViewHelperTest.php +++ /dev/null @@ -1,107 +0,0 @@ -flush(); - rmdir(self::$cachePath); - } - - protected function setUp(): void - { - if ((new Typo3Version())->getMajorVersion() >= 13) { - $this->coreExtensionsToLoad[] = 'typo3/cms-install'; - } - parent::setUp(); - } - - public static function renderDataProvider(): Generator - { - yield 'extension name empty, await else' => [ - '', - [], - 'elseArgument', - ]; - yield 'extension set to own, await then' => [ - '', - [], - 'thenArgument', - ]; - - yield 'extension set to non existent, await else' => [ - '', - [], - 'elseArgument', - ]; - - yield 'extension provided as undefined fluid variable placeholder, await else' => [ - '', - [], - 'elseArgument', - ]; - } - - /** - * @param array $variables - */ - #[DataProvider('renderDataProvider')] - #[Test] - public function render(string $template, array $variables, string $expected): void - { - if ((new Typo3Version())->getMajorVersion() < 13) { - $view = new TemplateView(); - $view->getRenderingContext()->getViewHelperResolver()->addNamespace('deepl', 'WebVision\\Deepltranslate\\Core\\ViewHelpers'); - $view->getRenderingContext()->setCache(self::$cache); - $view->getRenderingContext()->getTemplatePaths()->setTemplateSource($template); - } else { - $view = GeneralUtility::makeInstance(ViewFactoryInterface::class)->create(new ViewFactoryData()); - $view->getRenderingContext()->getViewHelperResolver()->addNamespace('deepl', 'WebVision\\Deepltranslate\\Core\\ViewHelpers'); - $view->getRenderingContext()->setCache(self::$cache); - $view->getRenderingContext()->getTemplatePaths()->setTemplateSource($template); - } - $view->assignMultiple($variables); - static::assertSame($expected, $view->render()); - } -} diff --git a/ext_localconf.php b/ext_localconf.php index 65e139be..0a7550c0 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -19,11 +19,6 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass'][\WebVision\Deepltranslate\Core\Hooks\UsageProcessAfterFinishHook::class] = \WebVision\Deepltranslate\Core\Hooks\UsageProcessAfterFinishHook::class; - //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, - ]; - //xclass databaserecordlist for rendering custom checkboxes to toggle deepl selection in recordlist if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('gridelements') && !empty($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['gridelements']['nestingInListModule'])) { $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\TYPO3\CMS\Backend\RecordList\DatabaseRecordList::class] = [