diff --git a/Classes/DataProcessing/ItemsProcessor.php b/Classes/DataProcessing/ItemsProcessor.php index 77d8b75..3214892 100644 --- a/Classes/DataProcessing/ItemsProcessor.php +++ b/Classes/DataProcessing/ItemsProcessor.php @@ -4,6 +4,7 @@ namespace Supseven\Supi\DataProcessing; +use TYPO3\CMS\Core\Localization\LanguageServiceFactory; use TYPO3\CMS\Core\Utility\MathUtility; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface; @@ -13,15 +14,26 @@ */ class ItemsProcessor implements DataProcessorInterface { + public function __construct( + private readonly LanguageServiceFactory $languageServiceFactory, + ) { + } + public function process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData): array { // Generate URLs for policy pages foreach ($processedData['settings']['elements'] ?? [] as $i => $element) { foreach ($element['items'] ?? [] as $j => $item) { - $policy = $item['table']['policy'] ?? ''; - - if ($policy && MathUtility::canBeInterpretedAsInteger($policy)) { - $policy = $cObj->typoLink_URL(['parameter' => $policy, 'forceAbsoluteUrl' => true]); + $policy = (string)($item['table']['policy'] ?? ''); + + if ($policy) { + if (MathUtility::canBeInterpretedAsInteger($policy)) { + $policy = $cObj->typoLink_URL(['parameter' => $policy, 'forceAbsoluteUrl' => true]); + } elseif (str_starts_with($policy, 'LLL:')) { + $siteLanguage = $cObj->getRequest()->getAttribute('language'); + $languageService = $this->languageServiceFactory->createFromSiteLanguage($siteLanguage); + $policy = $languageService->sL($policy); + } } $processedData['settings']['elements'][$i]['items'][$j]['table']['policyUrl'] = $policy; diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index 8d62634..575f369 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -3,13 +3,8 @@ services: autowire: true autoconfigure: true - Supseven\Supi\DataProcessing\SettingsProcessor: - public: true - - Supseven\Supi\DataProcessing\TyposcriptProcessor: - public: true - - Supseven\Supi\DataProcessing\YoutubeProcessor: + Supseven\Supi\DataProcessing\: + resource: '../Classes/DataProcessing/*' public: true Supseven\Supi\ContentObject\SupiJsContentObject: diff --git a/Tests/DataProcessing/ItemsProcessorTest.php b/Tests/DataProcessing/ItemsProcessorTest.php index 72cb74d..b12f820 100644 --- a/Tests/DataProcessing/ItemsProcessorTest.php +++ b/Tests/DataProcessing/ItemsProcessorTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase; use Supseven\Supi\DataProcessing\ItemsProcessor; +use TYPO3\CMS\Core\Localization\LanguageServiceFactory; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; /** @@ -75,8 +76,12 @@ public function testProcess(): void $cObj = $this->createMock(ContentObjectRenderer::class); $cObj->expects(static::once())->method('typoLink_URL')->with(static::equalTo($ts))->willReturn($policyUrl); + $cObj->expects(static::never())->method('getRequest'); - $subject = new ItemsProcessor(); + $languageServiceFactory = $this->createMock(LanguageServiceFactory::class); + $languageServiceFactory->expects($this->never())->method('create'); + + $subject = new ItemsProcessor($languageServiceFactory); $actual = $subject->process($cObj, [], [], $vars); static::assertEquals($expected, $actual);