Skip to content

Commit 1c17637

Browse files
committed
[TASK] Make compatible with TYPO3 v14
1 parent fee79e0 commit 1c17637

23 files changed

Lines changed: 196 additions & 195 deletions

Build/php-cs-fixer/config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
->setFinder(
4747
PhpCsFixer\Finder::create()
4848
->ignoreVCSIgnored(true)
49-
->in(realpath(__DIR__ . '/../../'))
49+
->in(realpath(__DIR__ . '/../ew-llxml2xliff/'))
5050
->exclude('bin')
5151
->exclude('public')
5252
->exclude('typo3temp')

Build/php-cs-fixer/header-comment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
$finder = PhpCsFixer\Finder::create()
3333
->name('*.php')
34-
->in(__DIR__ . '/../../')
34+
->in(__DIR__ . '/../ew-llxml2xliff/')
3535
->exclude('Acceptance/Support/_generated') // EXT:core
3636
->exclude('Build')
3737
// Configuration files do not need header comments

Classes/Controller/FileController.php

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* It is free software; you can redistribute it and/or modify it under
99
* the terms of the GNU General Public License, either version 2
10-
* of the License, or any later version.
10+
* of the License or any later version.
1111
*
1212
* For the full copyright and license information, please read the
1313
* LICENSE.txt file that was distributed with this source code.
@@ -21,6 +21,7 @@
2121
use Psr\Http\Message\ServerRequestInterface;
2222
use TYPO3\CMS\Backend\Attribute\AsController;
2323
use TYPO3\CMS\Backend\Routing\UriBuilder;
24+
use TYPO3\CMS\Backend\Template\Components\ComponentFactory;
2425
use TYPO3\CMS\Backend\Template\ModuleTemplate;
2526
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
2627
use TYPO3\CMS\Core\Http\PropagateResponseException;
@@ -39,16 +40,14 @@ public function __construct(
3940
protected ModuleTemplateFactory $moduleTemplateFactory,
4041
protected Converter $fileConverter,
4142
protected ExtensionService $extensionService,
43+
protected ComponentFactory $componentFactory,
4244
) {}
4345

4446
public function selectExtensionAction(ServerRequestInterface $request): ResponseInterface
4547
{
4648
[$extensions] = $this->prepareExtensions($request, false);
4749

48-
$moduleTemplate = $this->initializeModuleTemplate(
49-
$request,
50-
'LLL:EXT:ew_llxml2xliff/Resources/Private/Language/locallang.xlf:extension'
51-
);
50+
$moduleTemplate = $this->initializeModuleTemplate($request, 'ew_llxml2xliff.messages:extension');
5251
$moduleTemplate->assign('extensions', $extensions);
5352
return $moduleTemplate->renderResponse('File/SelectExtension');
5453
}
@@ -58,10 +57,7 @@ public function selectFileAction(ServerRequestInterface $request): ResponseInter
5857
[$extensions, $selectedExtension, $selectedExtensionKey] = $this->prepareExtensions($request);
5958
[$files] = $this->prepareFiles($request, $selectedExtensionKey, false);
6059

61-
$moduleTemplate = $this->initializeModuleTemplate(
62-
$request,
63-
'LLL:EXT:ew_llxml2xliff/Resources/Private/Language/locallang.xlf:file'
64-
);
60+
$moduleTemplate = $this->initializeModuleTemplate($request, 'ew_llxml2xliff.messages:file');
6561
$moduleTemplate->assignMultiple([
6662
'extensions' => $extensions,
6763
'selectedExtension' => $selectedExtension,
@@ -76,10 +72,7 @@ public function confirmConversionAction(ServerRequestInterface $request): Respon
7672
[$extensions, $selectedExtension, $selectedExtensionKey] = $this->prepareExtensions($request);
7773
[$files, $selectedFile, $selectedFileKey] = $this->prepareFiles($request, $selectedExtensionKey);
7874

79-
$moduleTemplate = $this->initializeModuleTemplate(
80-
$request,
81-
'LLL:EXT:ew_llxml2xliff/Resources/Private/Language/locallang.xlf:confirm_selection'
82-
);
75+
$moduleTemplate = $this->initializeModuleTemplate($request, 'ew_llxml2xliff.messages:confirm_selection');
8376
$moduleTemplate->assignMultiple([
8477
'extensions' => $extensions,
8578
'selectedExtension' => $selectedExtension,
@@ -99,10 +92,7 @@ public function convertFileAction(ServerRequestInterface $request): ResponseInte
9992
$conversionResult = $this->extensionService
10093
->convertLanguageFile($selectedExtensionKey, $selectedFileKey, $files);
10194

102-
$moduleTemplate = $this->initializeModuleTemplate(
103-
$request,
104-
'LLL:EXT:ew_llxml2xliff/Resources/Private/Language/locallang.xlf:finish'
105-
);
95+
$moduleTemplate = $this->initializeModuleTemplate($request, 'ew_llxml2xliff.messages:finish');
10696
$moduleTemplate->assignMultiple([
10797
'extensions' => $extensions,
10898
'selectedExtension' => $selectedExtension,
@@ -117,7 +107,6 @@ public function convertFileAction(ServerRequestInterface $request): ResponseInte
117107

118108
/**
119109
* @return array<string|array<array<string, string>>>
120-
* @throws PropagateResponseException
121110
*/
122111
protected function prepareExtensions(ServerRequestInterface $request, bool $selected = true): array
123112
{
@@ -139,7 +128,6 @@ protected function prepareExtensions(ServerRequestInterface $request, bool $sele
139128

140129
/**
141130
* @return array<string|array<array<string, string>>>
142-
* @throws PropagateResponseException
143131
*/
144132
protected function prepareFiles(ServerRequestInterface $request, string $extension, bool $selected = true): array
145133
{
@@ -161,25 +149,23 @@ protected function prepareFiles(ServerRequestInterface $request, string $extensi
161149

162150
/**
163151
* @param array<string, mixed> $extensions
164-
* @throws PropagateResponseException
165152
*/
166153
protected function getSelectedExtension(ServerRequestInterface $request, array $extensions): string
167154
{
168155
$selectedExtension = $this->isArgumentSetAndAvailable($request, $extensions, 'extension');
169-
if (!$selectedExtension) {
156+
if ($selectedExtension === '') {
170157
throw new PropagateResponseException($this->selectExtensionAction($request));
171158
}
172159
return $selectedExtension;
173160
}
174161

175162
/**
176163
* @param array<string, mixed> $files
177-
* @throws PropagateResponseException
178164
*/
179165
protected function getSelectedFile(ServerRequestInterface $request, array $files): string
180166
{
181167
$selectedFile = $this->isArgumentSetAndAvailable($request, $files, 'file');
182-
if (!$selectedFile) {
168+
if ($selectedFile === '') {
183169
throw new PropagateResponseException($this->selectFileAction($request));
184170
}
185171
return $selectedFile;
@@ -188,34 +174,31 @@ protected function getSelectedFile(ServerRequestInterface $request, array $files
188174
/**
189175
* @param array<string, mixed> $values
190176
*/
191-
protected function isArgumentSetAndAvailable(ServerRequestInterface $request, array $values, string $key): ?string
177+
protected function isArgumentSetAndAvailable(ServerRequestInterface $request, array $values, string $key): string
192178
{
193-
$formFieldValue = (string)($request->getParsedBody()[$key] ?? $request->getQueryParams()[$key] ?? '');
194-
return ($formFieldValue !== '' && isset($values[$formFieldValue])) ? $formFieldValue : null;
179+
$moduleData = $request->getAttribute('moduleData');
180+
$moduleData->cleanUp(['extension', 'file']);
181+
$formFieldValue = $moduleData->get($key);
182+
return ($formFieldValue !== '' && isset($values[$formFieldValue])) ? $formFieldValue : '';
195183
}
196184

197185
protected function initializeModuleTemplate(ServerRequestInterface $request, string $context): ModuleTemplate
198186
{
199-
$this->pageRenderer->addCssFile('EXT:ew_llxml2xliff/Resources/Public/Css/form.css');
200-
201187
$moduleTemplate = $this->moduleTemplateFactory->create($request);
202188
$moduleTemplate->setTitle(
203-
$this->getLanguageService()->sL(
204-
'LLL:EXT:ew_llxml2xliff/Resources/Private/Language/locallang_mod.xlf:mlang_tabs_tab'
205-
),
189+
$this->getLanguageService()->sL('ew_llxml2xliff.mod:title'),
206190
$this->getLanguageService()->sL($context)
207191
);
208192

209-
$buttonBar = $moduleTemplate->getDocHeaderComponent()->getButtonBar();
210-
211193
try {
194+
$buttonBar = $moduleTemplate->getDocHeaderComponent()->getButtonBar();
212195
$newFileConversionUrl = (string)$this->uriBuilder->buildUriFromRoute('web_EwLlxml2xliff');
213-
$newFileConversionButton = $buttonBar->makeLinkButton()
196+
$newFileConversionButton = $this->componentFactory->createLinkButton()
214197
->setDataAttributes(['identifier' => 'newFileConversion'])
215198
->setHref($newFileConversionUrl)
216199
->setTitle(
217200
$this->getLanguageService()->sL(
218-
'LLL:EXT:ew_llxml2xliff/Resources/Private/Language/locallang.xlf:start_new_conversion'
201+
'ew_llxml2xliff.messages:start_new_conversion'
219202
)
220203
)
221204
->setShowLabelText(true)

Classes/File/Converter.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* It is free software; you can redistribute it and/or modify it under
99
* the terms of the GNU General Public License, either version 2
10-
* of the License, or any later version.
10+
* of the License or any later version.
1111
*
1212
* For the full copyright and license information, please read the
1313
* LICENSE.txt file that was distributed with this source code.
@@ -16,6 +16,7 @@
1616
namespace Evoweb\EwLlxml2xliff\File;
1717

1818
use Evoweb\EwLlxml2xliff\Localization\Parser\LocallangXmlParser;
19+
use RuntimeException;
1920
use TYPO3\CMS\Core\Core\Environment;
2021
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
2122
use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -78,7 +79,7 @@ public function writeXmlAsXlfFilesInPlace(string $sourceFile): string
7879
}
7980

8081
/**
81-
* Function to convert php language files
82+
* Function to convert PHP language files
8283
*
8384
* @param string $sourceFile Absolute path to the selected ll-XML file
8485
*/
@@ -118,7 +119,7 @@ protected function getAvailableTranslations(string $languageFile): array
118119
}
119120

120121
if (empty($languages)) {
121-
throw new \RuntimeException('data section not found in "' . $languageFile . '"', 1314187884);
122+
throw new RuntimeException('data section not found in "' . $languageFile . '"', 1314187884);
122123
}
123124

124125
return $languages;
@@ -146,7 +147,7 @@ protected function localizedFileRef(string $fileRef, string $lang): string
146147
* Processing of the submitted form; Will create and write the XLIFF file and tell the new file name.
147148
*
148149
* @param string $xmlFile Absolute path to the locallang.xml file to convert
149-
* @param string $newFileName The new file name to write to (absolute path, .xlf ending)
150+
* @param string $newFileName The new file name to write to (an absolute path, .xlf ending)
150151
* @param string $langKey The language key
151152
*
152153
* @return string HTML text string message
@@ -158,7 +159,7 @@ protected function writeNewXliffFile(string $xmlFile, string $newFileName, strin
158159
$result = '';
159160
if (!@file_exists($newFileName)) {
160161
GeneralUtility::writeFile($newFileName, $xml);
161-
$result = str_replace(Environment::getComposerRootPath(), '', $newFileName);
162+
$result = str_replace(Environment::getProjectPath(), '', $newFileName);
162163
}
163164

164165
return $result;
@@ -199,7 +200,7 @@ protected function getOriginalFileName(string $filename, string $langKey): strin
199200
* Reads/Requires locallang files and returns raw $LOCAL_LANG array
200201
* @param string $languageFile Absolute reference to the ll-XML locallang file.
201202
* @return array<string, array<string, string>> LOCAL_LANG array from ll-XML file
202-
* (with all possible sub-files for languages included)
203+
* (with all possible subfiles for languages included)
203204
*/
204205
protected function getCombinedTranslationFileContent(string $languageFile): array
205206
{
@@ -221,7 +222,7 @@ protected function getCombinedTranslationFileContent(string $languageFile): arra
221222
}
222223

223224
if (empty($includedLanguages)) {
224-
throw new \RuntimeException('data section not found in "' . $languageFile . '"', 1314187884);
225+
throw new RuntimeException('data section not found in "' . $languageFile . '"', 1314187884);
225226
}
226227

227228
return $LOCAL_LANG;

Classes/File/TransUnit.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* It is free software; you can redistribute it and/or modify it under
99
* the terms of the GNU General Public License, either version 2
10-
* of the License, or any later version.
10+
* of the License or any later version.
1111
*
1212
* For the full copyright and license information, please read the
1313
* LICENSE.txt file that was distributed with this source code.
@@ -22,9 +22,6 @@
2222
protected string $target;
2323

2424
/**
25-
* @param string|array<string, string> $data
26-
* @param string $key
27-
* @param string $langKey
2825
* @param array<string, array<string, string>> $LOCAL_LANG
2926
*/
3027
public function __construct(

0 commit comments

Comments
 (0)