diff --git a/Classes/Override/Core12/DatabaseRecordList.php b/Classes/Override/Core12/DatabaseRecordList.php index 208813c4..4340ce1c 100644 --- a/Classes/Override/Core12/DatabaseRecordList.php +++ b/Classes/Override/Core12/DatabaseRecordList.php @@ -5,10 +5,14 @@ namespace WebVision\Deepltranslate\Core\Override\Core12; use WebVision\Deepltranslate\Core\Access\AllowedTranslateAccess; +use WebVision\Deepltranslate\Core\Event\DisallowTableFromDeeplTranslateEvent; use WebVision\Deepltranslate\Core\Utility\DeeplBackendUtility; /** * Class for rendering of Web>List module + * + * @internal + * @override */ class DatabaseRecordList extends \TYPO3\CMS\Backend\RecordList\DatabaseRecordList { @@ -28,8 +32,9 @@ public function makeLocalizationPanel($table, $row, array $translations): string return $out; } - // glossaries should not be auto translated by DeepL - if ($table === 'tx_wvdeepltranslate_glossaryentry') { + $tableDisallowedEvent = new DisallowTableFromDeeplTranslateEvent($table); + $this->eventDispatcher->dispatch($tableDisallowedEvent); + if ($tableDisallowedEvent->isTranslateButtonsAllowed() === false) { return $out; } diff --git a/Classes/Override/LocalizationController.php b/Classes/Override/LocalizationController.php index 095b1e65..65cfeb16 100644 --- a/Classes/Override/LocalizationController.php +++ b/Classes/Override/LocalizationController.php @@ -4,19 +4,13 @@ namespace WebVision\Deepltranslate\Core\Override; -use Doctrine\DBAL\Driver\Exception; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider; -use TYPO3\CMS\Backend\Controller\Event\AfterRecordSummaryForLocalizationEvent; -use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\DataHandling\DataHandler; use TYPO3\CMS\Core\Http\JsonResponse; use TYPO3\CMS\Core\Http\Response; -use TYPO3\CMS\Core\Imaging\Icon; use TYPO3\CMS\Core\Page\PageRenderer; use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Core\Versioning\VersionState; use WebVision\Deepltranslate\Core\Service\DeeplService; /** @@ -44,133 +38,6 @@ public function __construct() $this->pageRenderer->addInlineLanguageLabelFile('EXT:deepltranslate_core/Resources/Private/Language/locallang.xlf'); } - /** - * Get used languages in a page - */ - public function getUsedLanguagesInPage(ServerRequestInterface $request): ResponseInterface - { - $params = $request->getQueryParams(); - if (!isset($params['pageId'], $params['languageId'])) { - return new JsonResponse(null, 400); - } - - $pageId = (int)$params['pageId']; - $languageId = (int)$params['languageId']; - $mode = $params['mode'] ?? ''; - - /** @var TranslationConfigurationProvider $translationProvider */ - $translationProvider = GeneralUtility::makeInstance(TranslationConfigurationProvider::class); - $systemLanguages = $translationProvider->getSystemLanguages($pageId); - - $availableLanguages = []; - - // First check whether column has localized records - $elementsInColumnCount = $this->localizationRepository->getLocalizedRecordCount($pageId, $languageId); - $result = []; - if ($elementsInColumnCount !== 0) { - // check elements in column - empty if source records do not exist anymore - $result = $this->localizationRepository->fetchOriginLanguage($pageId, $languageId); - if ($result !== []) { - $availableLanguages[] = $systemLanguages[$result['sys_language_uid']]; - } - } - if ($elementsInColumnCount === 0 || $result === []) { - $fetchedAvailableLanguages = $this->localizationRepository->fetchAvailableLanguages($pageId, $languageId); - foreach ($fetchedAvailableLanguages as $language) { - if (isset($systemLanguages[$language['sys_language_uid']])) { - $availableLanguages[] = $systemLanguages[$language['sys_language_uid']]; - } - } - } - // Language "All" should not appear as a source of translations (see bug 92757) and keys should be sequential - $availableLanguages = array_values( - array_filter($availableLanguages, static function (array $languageRecord): bool { - return (int)$languageRecord['uid'] !== -1; - }) - ); - - //for DeepL auto mode - if (!empty($availableLanguages)) { - if ($mode == 'localizedeeplauto') { - foreach ($availableLanguages as &$availableLanguage) { - $availableLanguage['uid'] = 'auto-' . $availableLanguage['uid']; - $availableLanguage['ISOcode'] = 'AUT'; - } - } - } - - // Pre-render all flag icons - foreach ($availableLanguages as &$language) { - if ($language['flagIcon'] === 'empty-empty') { - $language['flagIcon'] = ''; - } else { - $language['flagIcon'] = $this->iconFactory->getIcon($language['flagIcon'], Icon::SIZE_SMALL)->render(); - } - } - - return (new JsonResponse())->setPayload($availableLanguages); - } - - /** - * Get a prepared summary of records being translated - * - * @param ServerRequestInterface $request - * @return ResponseInterface - * @throws Exception - */ - public function getRecordLocalizeSummary(ServerRequestInterface $request): ResponseInterface - { - $params = $request->getQueryParams(); - if (!isset($params['pageId'], $params['destLanguageId'], $params['languageId'])) { - return new JsonResponse(null, 400); - } - - $pageId = (int)$params['pageId']; - $destLanguageId = (int)$params['destLanguageId']; - //getting source language id - $languageId = $this->getSourceLanguageId($params['languageId']); - - $records = []; - $result = $this->localizationRepository->getRecordsToCopyDatabaseResult( - $pageId, - $destLanguageId, - $languageId, - '*' - ); - - $flatRecords = []; - while ($row = $result->fetchAssociative()) { - BackendUtility::workspaceOL('tt_content', $row, -99, true); - if (!$row || VersionState::cast($row['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) { - continue; - } - $colPos = $row['colPos']; - if (!isset($records[$colPos])) { - $records[$colPos] = []; - } - $records[$colPos][] = [ - 'icon' => $this->iconFactory->getIconForRecord('tt_content', $row, Icon::SIZE_SMALL)->render(), - 'title' => $row[$GLOBALS['TCA']['tt_content']['ctrl']['label']], - 'uid' => $row['uid'], - ]; - $flatRecords[] = $row; - } - - $payloadBody = [ - 'records' => $records, - 'columns' => $this->getPageColumns($pageId, $flatRecords, $params), - ]; - - $event = new AfterRecordSummaryForLocalizationEvent($payloadBody['records'], $payloadBody['columns']); - $this->eventDispatcher->dispatch($event); - $payloadBody = [ - 'records' => $event->getRecords(), - 'columns' => $event->getColumns(), - ]; - - return (new JsonResponse())->setPayload($payloadBody); - } - /** * @param ServerRequestInterface $request * @return ResponseInterface