Skip to content

Commit 92c96fe

Browse files
authored
Merge pull request #76 from FriendsOfTYPO3/feature/add-typo3v14-support
Feature/add typo3v14 support
2 parents d19c2e0 + c8b0a9f commit 92c96fe

File tree

19 files changed

+621
-276
lines changed

19 files changed

+621
-276
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,24 @@ jobs:
1818
typo3-versions: '^12'
1919
- php-versions: '8.2'
2020
typo3-versions: '^13'
21+
- php-versions: '8.2'
22+
typo3-versions: '14.*.*@dev'
2123
- php-versions: '8.3'
2224
typo3-versions: '^12'
2325
- php-versions: '8.3'
2426
typo3-versions: '^13'
27+
- php-versions: '8.3'
28+
typo3-versions: '14.*.*@dev'
2529
- php-versions: '8.4'
2630
typo3-versions: '^12'
2731
- php-versions: '8.4'
2832
typo3-versions: '^13'
33+
- php-versions: '8.4'
34+
typo3-versions: '14.*.*@dev'
2935
- php-versions: '8.5'
3036
typo3-versions: '^13'
37+
- php-versions: '8.5'
38+
typo3-versions: '14.*.*@dev'
3139
steps:
3240
- name: Check out repository
3341
uses: actions/checkout@v5
@@ -53,7 +61,12 @@ jobs:
5361
composer require typo3/cms-core=${{ matrix.typo3-versions }} --no-progress --prefer-dist --optimize-autoloader
5462
- name: Run PHP linter
5563
run: |
56-
find . -type f -name '*.php' ! -path "./.Build/*" -print0 | xargs -0 -n1 -P4 php -l -n | (! grep -v "No syntax errors detected" )
64+
PHP_VERSION=$(php -r "echo PHP_VERSION_ID;")
65+
if [[ $PHP_VERSION -ge 80200 ]]; then
66+
find . -type f -name '*.php' ! -path "./.Build/*" -print0 | xargs -0 -n1 -P4 php -l -n | (! grep -v "No syntax errors detected" )
67+
else
68+
find . -type f -name '*.php' ! -path "./.Build/*" ! -path './*/V14/*' -print0 | xargs -0 -n1 -P4 php -l -n | (! grep -v "No syntax errors detected" )
69+
fi
5770
- name: Run unit tests
5871
run: |
5972
.Build/bin/phpunit -c Tests/phpunit.xml.dist

Classes/Backend/ToolbarItems/CrowdinToolbarItem.php

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
use TYPO3\CMS\Core\Http\JsonResponse;
1616
use TYPO3\CMS\Core\Imaging\IconFactory;
1717
use TYPO3\CMS\Core\Information\Typo3Version;
18+
use TYPO3\CMS\Core\Package\PackageManager;
1819
use TYPO3\CMS\Core\Page\JavaScriptModuleInstruction;
1920
use TYPO3\CMS\Core\Page\PageRenderer;
21+
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
2022
use TYPO3\CMS\Core\Utility\GeneralUtility;
21-
use TYPO3\CMS\Extensionmanager\Utility\ListUtility;
23+
use TYPO3\CMS\Core\Utility\PathUtility;
2224

2325
class CrowdinToolbarItem implements ToolbarItemInterface
2426
{
@@ -28,7 +30,8 @@ class CrowdinToolbarItem implements ToolbarItemInterface
2830

2931
public function __construct(
3032
private readonly PageRenderer $pageRenderer,
31-
private readonly IconFactory $iconFactory
33+
private readonly IconFactory $iconFactory,
34+
private readonly PackageManager $packageManager
3235
) {
3336
$this->typo3Version = (new Typo3Version())->getMajorVersion();
3437

@@ -107,8 +110,6 @@ protected function createToggleSwitch(string $name, bool $enabled): string
107110
'itemFormElValue' => $enabled ? 1 : 0,
108111
'fieldConf' => [
109112
'config' => [
110-
// "items" is needed for TYPO3 v11
111-
'items' => [],
112113
'readOnly' => false,
113114
],
114115
],
@@ -166,12 +167,11 @@ protected function getExtensionsCompatibleWithCrowdin(): array
166167
return !empty($languageFiles);
167168
});
168169

169-
$listUtility = GeneralUtility::makeInstance(ListUtility::class);
170-
$availableExtensions = $listUtility->getAvailableExtensions();
170+
$availableExtensions = $this->getAvailableExtensions();
171171
$thirdPartyExtensions = array_diff_key($availableExtensions, array_flip(LanguageServiceXclassed::CORE_EXTENSIONS));
172172

173173
foreach ($thirdPartyExtensions as $extension) {
174-
if (in_array($extension['key'], $compatibleExtensions)) {
174+
if (in_array($extension['key'], $compatibleExtensions, true)) {
175175
$extensions[$extension['key']] = [
176176
'key' => $extension['key'],
177177
'name' => $extension['title'],
@@ -254,4 +254,29 @@ public function setCurrentExtension(ServerRequestInterface $request): ResponseIn
254254
'success' => true,
255255
]);
256256
}
257+
258+
/**
259+
* Largely inspired from @see \TYPO3\CMS\Extensionmanager\Utility\ListUtility::getAvailableExtensions())
260+
*/
261+
private function getAvailableExtensions(): array
262+
{
263+
$availableExtensions = [];
264+
foreach ($this->packageManager->getAvailablePackages() as $package) {
265+
if (!$package->getPackageMetaData()->isExtensionType()) {
266+
continue;
267+
}
268+
if ($this->typo3Version >= 13) {
269+
$icon = $package->getPackageIcon();
270+
} else {
271+
$icon = ExtensionManagementUtility::getExtensionIcon($package->getPackagePath());
272+
}
273+
$extensionData = [
274+
'key' => $package->getPackageKey(),
275+
'icon' => $icon ? PathUtility::getAbsoluteWebPath($package->getPackagePath() . $icon) : '',
276+
'title' => $package->getPackageMetaData()->getTitle(),
277+
];
278+
$availableExtensions[$package->getPackageKey()] = $extensionData;
279+
}
280+
return $availableExtensions;
281+
}
257282
}

Classes/Setup.php

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace FriendsOfTYPO3\Crowdin;
66

77
use TYPO3\CMS\Core\Configuration\ConfigurationManager;
8+
use TYPO3\CMS\Core\Information\Typo3Version;
89
use TYPO3\CMS\Core\Utility\GeneralUtility;
910

1011
/**
@@ -15,6 +16,18 @@
1516
*/
1617
class Setup
1718
{
19+
private readonly string $overrideNamespace;
20+
21+
public function __construct()
22+
{
23+
$typo3Version = (new Typo3Version())->getMajorVersion();
24+
if ($typo3Version >= 14) {
25+
$this->overrideNamespace = 'FriendsOfTYPO3\\Crowdin\\ViewHelpers\\Override\\V14';
26+
} else {
27+
$this->overrideNamespace = 'FriendsOfTYPO3\\Crowdin\\ViewHelpers\\Override\\V12';
28+
}
29+
}
30+
1831
public function enable(): void
1932
{
2033
$configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
@@ -26,14 +39,15 @@ public function enable(): void
2639
$changesToBeWritten = true;
2740
}
2841

29-
if (!in_array('FriendsOfTYPO3\\Crowdin\\ViewHelpers\\Override', $localConfiguration['SYS']['fluid']['namespaces']['f'] ?? [], true)) {
42+
$changesToBeWritten |= $this->disableLegacyOverrides($localConfiguration);
43+
if (!in_array($this->overrideNamespace, $localConfiguration['SYS']['fluid']['namespaces']['f'] ?? [], true)) {
3044
if (!in_array('TYPO3\\CMS\\Fluid\\ViewHelpers', $localConfiguration['SYS']['fluid']['namespaces']['f'] ?? [], true)) {
3145
$localConfiguration['SYS']['fluid']['namespaces']['f'][] = 'TYPO3\\CMS\\Fluid\\ViewHelpers';
3246
}
3347
if (!in_array('TYPO3Fluid\\Fluid\\ViewHelpers', $localConfiguration['SYS']['fluid']['namespaces']['f'] ?? [], true)) {
3448
$localConfiguration['SYS']['fluid']['namespaces']['f'][] = 'TYPO3Fluid\\Fluid\\ViewHelpers';
3549
}
36-
$localConfiguration['SYS']['fluid']['namespaces']['f'][] = 'FriendsOfTYPO3\\Crowdin\\ViewHelpers\\Override';
50+
$localConfiguration['SYS']['fluid']['namespaces']['f'][] = $this->overrideNamespace;
3751
$changesToBeWritten = true;
3852
}
3953

@@ -47,14 +61,17 @@ public function disable(): void
4761
{
4862
$configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
4963
$localConfiguration = $configurationManager->getLocalConfiguration();
64+
5065
$changesToBeWritten = false;
5166
if (isset($localConfiguration['SYS']['localization']['locales']['user']['t3'])) {
5267
unset($localConfiguration['SYS']['localization']['locales']['user']['t3']);
5368
$changesToBeWritten = true;
5469
}
55-
if (in_array('FriendsOfTYPO3\\Crowdin\\ViewHelpers\\Override', $localConfiguration['SYS']['fluid']['namespaces']['f'] ?? [], true)) {
70+
71+
$changesToBeWritten |= $this->disableLegacyOverrides($localConfiguration);
72+
if (in_array($this->overrideNamespace, $localConfiguration['SYS']['fluid']['namespaces']['f'] ?? [], true)) {
5673
foreach ($localConfiguration['SYS']['fluid']['namespaces']['f'] as $k => $v) {
57-
if ($v === 'FriendsOfTYPO3\\Crowdin\\ViewHelpers\\Override') {
74+
if ($v === $this->overrideNamespace) {
5875
unset($localConfiguration['SYS']['fluid']['namespaces']['f'][$k]);
5976
$changesToBeWritten = true;
6077
}
@@ -63,9 +80,38 @@ public function disable(): void
6380
unset($localConfiguration['SYS']['fluid']['namespaces']['f']);
6481
}
6582
}
83+
6684
if ($changesToBeWritten) {
6785
$configurationManager->writeLocalConfiguration($localConfiguration);
6886
}
6987
}
7088

89+
/**
90+
* Disables the legacy overrides from the configuration.
91+
*
92+
* @param array $localConfiguration
93+
* @return bool
94+
* @todo can be removed once v4.0 is "largely" in use
95+
*/
96+
private function disableLegacyOverrides(array &$localConfiguration): bool
97+
{
98+
$legacyOverrideNamespaces = [
99+
// Version 3.x
100+
'FriendsOfTYPO3\\Crowdin\\ViewHelpers\\Override',
101+
// Version 2.x or below
102+
'GeorgRinger\\Crowdin\\ViewHelpers\\Override',
103+
];
104+
$changesToBeWritten = false;
105+
foreach ($legacyOverrideNamespaces as $legacyOverrideNamespace) {
106+
if (in_array($legacyOverrideNamespace, $localConfiguration['SYS']['fluid']['namespaces']['f'] ?? [], true)) {
107+
foreach ($localConfiguration['SYS']['fluid']['namespaces']['f'] as $k => $v) {
108+
if ($v === $legacyOverrideNamespace) {
109+
unset($localConfiguration['SYS']['fluid']['namespaces']['f'][$k]);
110+
$changesToBeWritten = true;
111+
}
112+
}
113+
}
114+
}
115+
return $changesToBeWritten;
116+
}
71117
}

Classes/ViewHelpers/Override/TranslateViewHelper.php

Lines changed: 0 additions & 178 deletions
This file was deleted.

0 commit comments

Comments
 (0)