From 5ed8a09f207368da2f2d25a9ac8b2692010c8ce1 Mon Sep 17 00:00:00 2001 From: Nimmermaer Date: Mon, 10 Feb 2025 16:26:49 +0100 Subject: [PATCH] [BUGFIX] Move instantiation of LanguageService and FileRepository The `__construct` method in `ShowDeleteFiles` caused an autowiring issue due to `LanguageService` being excluded in `Configuration/Services.yaml`. To resolve this, the instantiation of `LanguageService` and `FileRepository` was moved to the respective methods using `GeneralUtility::makeInstance()`. --- Classes/Form/Element/ShowDeleteFiles.php | 27 +++++++++-------------- Classes/Form/Element/ShowMissingFiles.php | 22 ++++++++---------- 2 files changed, 20 insertions(+), 29 deletions(-) diff --git a/Classes/Form/Element/ShowDeleteFiles.php b/Classes/Form/Element/ShowDeleteFiles.php index ffee4d5..ad5b9b2 100644 --- a/Classes/Form/Element/ShowDeleteFiles.php +++ b/Classes/Form/Element/ShowDeleteFiles.php @@ -26,17 +26,7 @@ class ShowDeleteFiles extends AbstractFormElement { - /** - * Container objects give $nodeFactory down to other containers. - * - * @param FileRepository $fileRepository - * @param LanguageService $languageService - */ - public function __construct( - protected readonly FileRepository $fileRepository, - protected readonly LanguageService $languageService - ) { - } + /** * @return array @@ -44,8 +34,9 @@ public function __construct( public function render(): array { $result = $this->initializeResultArray(); - - $rows = $this->fileRepository->countByIdentifier($this->data['vanillaUid']); + $languageService = $this->instanceLanguageService(); + $fileRepository = GeneralUtility::makeInstance(FileRepository::class); + $rows = $fileRepository->countByIdentifier($this->data['vanillaUid']); // TODO https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/13.0/Breaking-97330-FormEngineElementClassesMustCreateLabelOrLegend.html @@ -54,7 +45,7 @@ public function render(): array if (empty($rows)) { $html[] = '' - . $this->languageService->sL('LLL:EXT:filefill/Resources/Private/Language/locallang_db.xlf:sys_file_storage.filefill.no_delete') + . $languageService->sL('LLL:EXT:filefill/Resources/Private/Language/locallang_db.xlf:sys_file_storage.filefill.no_delete') . ''; } else { $iconFactory = GeneralUtility::makeInstance(IconFactory::class); @@ -65,9 +56,9 @@ public function render(): array $html[] = ''; $html[] = $iconFactory->getIcon('actions-edit-delete', IconSize::SMALL); $html[] = ' ' . sprintf( - $this->languageService->sL('LLL:EXT:filefill/Resources/Private/Language/locallang_db.xlf:sys_file_storage.filefill.delete_files'), + $languageService->sL('LLL:EXT:filefill/Resources/Private/Language/locallang_db.xlf:sys_file_storage.filefill.delete_files'), $row['count'], - $this->languageService->sL($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['filefill']['resourceHandler'][$row['tx_filefill_identifier']]['title'] ?? $row['tx_filefill_identifier']) + $languageService->sL($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['filefill']['resourceHandler'][$row['tx_filefill_identifier']]['title'] ?? $row['tx_filefill_identifier']) ); $html[] = ''; } @@ -78,4 +69,8 @@ public function render(): array return $result; } + private function instanceLanguageService(): LanguageService + { + return $GLOBALS['LANG']; + } } diff --git a/Classes/Form/Element/ShowMissingFiles.php b/Classes/Form/Element/ShowMissingFiles.php index ee53b48..0f1d6cf 100644 --- a/Classes/Form/Element/ShowMissingFiles.php +++ b/Classes/Form/Element/ShowMissingFiles.php @@ -27,15 +27,6 @@ class ShowMissingFiles extends AbstractFormElement { - /** - * Container objects give $nodeFactory down to other containers. - * - * @param LanguageService|null $languageService - * @throws \InvalidArgumentException - */ - public function __construct(protected readonly LanguageService $languageService) - { - } /** * @return array @@ -43,7 +34,7 @@ public function __construct(protected readonly LanguageService $languageService) public function render(): array { $result = $this->initializeResultArray(); - + $languageService = $this->instanceLanguageService(); $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file'); $expressionBuilder = $queryBuilder->expr(); $count = $queryBuilder->count('*') @@ -68,13 +59,13 @@ public function render(): array if ($count === 0) { $html[] = '' - . $this->languageService->sL('LLL:EXT:filefill/Resources/Private/Language/locallang_db.xlf:sys_file_storage.filefill.no_missing') + . $languageService->sL('LLL:EXT:filefill/Resources/Private/Language/locallang_db.xlf:sys_file_storage.filefill.no_missing') . ''; } else { $iconFactory = GeneralUtility::makeInstance(IconFactory::class); $html[] = '' . sprintf( - $this->languageService->sL('LLL:EXT:filefill/Resources/Private/Language/locallang_db.xlf:sys_file_storage.filefill.missing_files'), + $languageService->sL('LLL:EXT:filefill/Resources/Private/Language/locallang_db.xlf:sys_file_storage.filefill.missing_files'), $count ) . ''; @@ -82,7 +73,7 @@ public function render(): array $html[] = '
'; $html[] = ''; $html[] = $iconFactory->getIcon('actions-database-reload', IconSize::SMALL); - $html[] = ' ' . $this->languageService->sL('LLL:EXT:filefill/Resources/Private/Language/locallang_db.xlf:sys_file_storage.filefill.reset'); + $html[] = ' ' . $languageService->sL('LLL:EXT:filefill/Resources/Private/Language/locallang_db.xlf:sys_file_storage.filefill.reset'); $html[] = ''; } @@ -92,4 +83,9 @@ public function render(): array return $result; } + + private function instanceLanguageService(): LanguageService + { + return $GLOBALS['LANG']; + } }