Skip to content

Commit 62cf77f

Browse files
author
Mathis Koblin
committed
Upgraded code to TYPO3 v13
1 parent 7a646fa commit 62cf77f

29 files changed

+290
-295
lines changed

Classes/Controller/PreviewImageFlushController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Psr\Http\Message\ResponseInterface;
99
use Psr\Http\Message\ServerRequestInterface;
1010
use TYPO3\CMS\Core\Http\JsonResponse;
11-
use TYPO3\CMS\Core\Messaging\AbstractMessage;
11+
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
1212
use TYPO3\CMS\Core\Utility\GeneralUtility;
1313

1414
class PreviewImageFlushController
@@ -18,20 +18,20 @@ public function flush(ServerRequestInterface $serverRequest): ResponseInterface
1818
$youtubeId = $serverRequest->getParsedBody()['id'] ?? null;
1919
$type = $serverRequest->getParsedBody()['type'] ?? null;
2020
if ($youtubeId === null) {
21-
return new JsonResponse(['status' => AbstractMessage::ERROR, 'message' => 'Missing id']);
21+
return new JsonResponse(['status' => ContextualFeedbackSeverity::ERROR, 'message' => 'Missing id']);
2222
}
2323
if ($type === null) {
24-
return new JsonResponse(['status' => AbstractMessage::ERROR, 'message' => 'Missing type']);
24+
return new JsonResponse(['status' => ContextualFeedbackSeverity::ERROR, 'message' => 'Missing type']);
2525
}
2626

2727
$previewImageServiceRegistry = GeneralUtility::makeInstance(PreviewImageServiceRegistry::class);
2828
$previewImageService = $previewImageServiceRegistry->getPreviewImageService($type);
2929

3030
if (!$previewImageService->hasPreviewImage($youtubeId)) {
31-
return new JsonResponse(['status' => AbstractMessage::INFO, 'message' => 'Preview image does not exist']);
31+
return new JsonResponse(['status' => ContextualFeedbackSeverity::INFO, 'message' => 'Preview image does not exist']);
3232
}
3333
$previewImageService->deletePreviewImage($youtubeId);
3434

35-
return new JsonResponse(['status' => AbstractMessage::OK, 'message' => 'Preview image deleted']);
35+
return new JsonResponse(['status' => ContextualFeedbackSeverity::OK, 'message' => 'Preview image deleted']);
3636
}
3737
}

Classes/Hooks/ContentPostProcessHook.php renamed to Classes/EventListener/ContentPostProcessEventListener.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,38 @@
22

33
declare(strict_types=1);
44

5-
namespace IchHabRecht\SocialGdpr\Hooks;
5+
namespace IchHabRecht\SocialGdpr\EventListener;
66

77
use IchHabRecht\SocialGdpr\Handler\ContentMatch;
88
use IchHabRecht\SocialGdpr\Handler\HandlerInterface;
9+
use Psr\Http\Message\ServerRequestInterface;
10+
use TYPO3\CMS\Core\Attribute\AsEventListener;
911
use TYPO3\CMS\Core\Utility\GeneralUtility;
1012
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
1113
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
14+
use TYPO3\CMS\Frontend\Event\AfterCacheableContentIsGeneratedEvent;
1215

13-
class ContentPostProcessHook
16+
#[AsEventListener(
17+
identifier: 'socialgdprAfterCacheableContentIsGeneratedEventListener',
18+
)]
19+
final readonly class ContentPostProcessEventListener
1420
{
1521
/**
1622
* @var ContentObjectRenderer|null
1723
*/
18-
protected $contentObjectRenderer;
24+
protected object $contentObjectRenderer;
1925

2026
public function __construct(ContentObjectRenderer $contentObjectRenderer = null)
2127
{
2228
$this->contentObjectRenderer = $contentObjectRenderer ?: GeneralUtility::makeInstance(ContentObjectRenderer::class);
2329
}
2430

25-
public function replaceSocialMediaWithEvent(\TYPO3\CMS\Frontend\Event\AfterCacheableContentIsGeneratedEvent $event)
31+
public function __invoke(AfterCacheableContentIsGeneratedEvent $event): void
2632
{
27-
$this->replaceSocialMediaInContent($event->getController());
33+
$this->replaceSocialMediaInContent($event->getController(), $event->getRequest());
2834
}
2935

30-
public function replaceSocialMedia(array $parameter)
31-
{
32-
$this->replaceSocialMediaInContent($parameter['pObj']);
33-
}
34-
35-
protected function replaceSocialMediaInContent(TypoScriptFrontendController $typoScriptFrontendController)
36+
protected function replaceSocialMediaInContent(TypoScriptFrontendController $typoScriptFrontendController, ServerRequestInterface $request): void
3637
{
3738
$content = $typoScriptFrontendController->content;
3839

@@ -63,7 +64,8 @@ protected function replaceSocialMediaInContent(TypoScriptFrontendController $typ
6364
);
6465

6566
$this->contentObjectRenderer->start($data, 'tt_content');
66-
$handlerContent = $this->contentObjectRenderer->cObjGetSingle($typoScriptFrontendController->tmpl->setup['lib.']['socialgdpr'], $typoScriptFrontendController->tmpl->setup['lib.']['socialgdpr.']);
67+
$typoScript = $request->getAttribute('frontend.typoscript')->getSetupArray();
68+
$handlerContent = $this->contentObjectRenderer->cObjGetSingle($typoScript['lib.']['socialgdpr'], $typoScript['lib.']['socialgdpr.']);
6769
$content = str_replace($match->getSearch(), $handlerContent, $content);
6870
}
6971
}

Classes/ExtensionConfiguration.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@
99

1010
class ExtensionConfiguration implements SingletonInterface
1111
{
12-
/**
13-
* @var array
14-
*/
15-
protected $settings = [];
12+
protected ?array $settings;
1613

17-
public function __construct(array $settings = null)
14+
public function __construct(?array $settings = null)
1815
{
1916
if ($settings === null) {
20-
if (class_exists('TYPO3\\CMS\\Core\\Configuration\\ExtensionConfiguration')) {
17+
if (class_exists(\TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class)) {
2118
$settings = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class)->get('social_gdpr');
2219
} else {
2320
$settings = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['social_gdpr'], ['allowed_classes' => false]);
@@ -26,7 +23,7 @@ public function __construct(array $settings = null)
2623
$this->settings = $settings;
2724
}
2825

29-
public function isEnabled($key)
26+
public function isEnabled($key): bool
3027
{
3128
return !empty($this->settings[$key]);
3229
}

Classes/Form/CustomInlineControl/OnlineFalMediaPreviewFlush.php renamed to Classes/Form/CustomInlineControl/OnlineFalMediaPreviewFlushEventListener.php

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
namespace IchHabRecht\SocialGdpr\Form\CustomInlineControl;
66

77
use IchHabRecht\SocialGdpr\Service\PreviewImageServiceRegistry;
8-
use TYPO3\CMS\Backend\Form\Element\InlineElementHookInterface;
98
use TYPO3\CMS\Backend\Form\Event\ModifyFileReferenceControlsEvent;
9+
use TYPO3\CMS\Backend\Form\Event\ModifyInlineElementControlsEvent;
10+
use TYPO3\CMS\Backend\Form\Event\ModifyInlineElementEnabledControlsEvent;
11+
use TYPO3\CMS\Core\Attribute\AsEventListener;
1012
use TYPO3\CMS\Core\Imaging\Icon;
1113
use TYPO3\CMS\Core\Imaging\IconFactory;
1214
use TYPO3\CMS\Core\Imaging\IconRegistry;
@@ -15,7 +17,18 @@
1517
use TYPO3\CMS\Core\Resource\ResourceFactory;
1618
use TYPO3\CMS\Core\Utility\GeneralUtility;
1719

18-
class OnlineFalMediaPreviewFlush implements InlineElementHookInterface
20+
21+
#[AsEventListener(
22+
identifier: 'socialgdprModifyFileReferenceControlsEvent',
23+
event: ModifyFileReferenceControlsEvent::class,
24+
method: 'renderFileReferenceHeaderControl',
25+
)]
26+
#[AsEventListener(
27+
identifier: 'socialgdprModifyInlineElementControlsEvent',
28+
event: ModifyInlineElementControlsEvent::class,
29+
method: 'modifyControls',
30+
)]
31+
class OnlineFalMediaPreviewFlushEventListener
1932
{
2033
protected IconFactory $iconFactory;
2134

@@ -30,12 +43,12 @@ class OnlineFalMediaPreviewFlush implements InlineElementHookInterface
3043
protected ResourceFactory $resourceFactory;
3144

3245
public function __construct(
33-
IconFactory $iconFactory = null,
34-
IconRegistry $iconRegistry = null,
35-
OnlineMediaHelperRegistry $onlineMediaRegistry = null,
36-
PageRenderer $pageRenderer = null,
37-
PreviewImageServiceRegistry $previewImageServiceRegistry = null,
38-
ResourceFactory $resourceFactory = null
46+
?IconFactory $iconFactory = null,
47+
?IconRegistry $iconRegistry = null,
48+
?OnlineMediaHelperRegistry $onlineMediaRegistry = null,
49+
?PageRenderer $pageRenderer = null,
50+
?PreviewImageServiceRegistry $previewImageServiceRegistry = null,
51+
?ResourceFactory $resourceFactory = null
3952
) {
4053
$this->iconFactory = $iconFactory ?: GeneralUtility::makeInstance(IconFactory::class);
4154
$this->iconRegistry = $iconRegistry ?: GeneralUtility::makeInstance(IconRegistry::class);
@@ -45,7 +58,7 @@ public function __construct(
4558
$this->resourceFactory = $resourceFactory ?: GeneralUtility::makeInstance(ResourceFactory::class);
4659
}
4760

48-
public function renderFileReferenceHeaderControl(ModifyFileReferenceControlsEvent $event)
61+
public function renderFileReferenceHeaderControl(ModifyFileReferenceControlsEvent $event): void
4962
{
5063
$elementData = $event->getElementData();
5164
if ($elementData['tableName'] !== 'sys_file_reference') {
@@ -61,32 +74,15 @@ public function renderFileReferenceHeaderControl(ModifyFileReferenceControlsEven
6174
return;
6275
}
6376

64-
$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/SocialGdpr/Backend/PreviewImageFlush');
77+
$this->pageRenderer->loadJavaScriptModule('@vendor/social_gdpr/Backend/PreviewImageFlush.js');
6578
$controls = $event->getControls();
6679
$controls['youtubeFlush'] = $this->renderControlItem($record);
6780
$event->setControls($controls);
6881
}
6982

70-
public function renderForeignRecordHeaderControl_preProcess(
71-
$parentUid,
72-
$foreignTable,
73-
array $childRecord,
74-
array $childConfig,
75-
$isVirtual,
76-
array &$enabledControls
77-
) {
78-
// Do nothing.
79-
}
80-
81-
public function renderForeignRecordHeaderControl_postProcess(
82-
$parentUid,
83-
$foreignTable,
84-
array $childRecord,
85-
array $childConfig,
86-
$isVirtual,
87-
array &$controlItems
88-
) {
89-
if ($foreignTable !== 'sys_file_reference') {
83+
public function modifyControls(ModifyInlineElementControlsEvent $event): void
84+
{
85+
if ($event->getElementData()['inlineParentTableName'] !== 'sys_file_reference') {
9086
return;
9187
}
9288

@@ -98,8 +94,9 @@ public function renderForeignRecordHeaderControl_postProcess(
9894
return;
9995
}
10096

101-
$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/SocialGdpr/Backend/PreviewImageFlush');
97+
$this->pageRenderer->loadJavaScriptModule('@vendor/social_gdpr/Backend/PreviewImageFlush.js');
10298
$controlItems['youtubeFlush'] = $this->renderControlItem($childRecord);
99+
$event->setControls($controlItems);
103100
}
104101

105102
protected function renderControlItem(array $record): string

Classes/Handler/ContentMatch.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,8 @@
66

77
class ContentMatch
88
{
9-
/**
10-
* @var array
11-
*/
12-
protected $data = [];
13-
14-
/**
15-
* @var string
16-
*/
17-
protected $search;
18-
19-
public function __construct(string $search, array $data = [])
9+
public function __construct(protected string $search, protected array $data = [])
2010
{
21-
$this->search = $search;
22-
$this->data = $data;
2311
}
2412

2513
public function getData(): array

Classes/Handler/GoogleMapsIframeHandler.php

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ class GoogleMapsIframeHandler implements HandlerInterface
1414
*/
1515
protected $matches = [];
1616

17-
/**
18-
* @param string $content
19-
* @return bool
20-
*/
2117
public function hasMatches(string $content): bool
2218
{
2319
preg_match_all(
@@ -36,17 +32,15 @@ public function hasMatches(string $content): bool
3632
public function getMatches(): array
3733
{
3834
return array_map(
39-
function ($match) {
40-
return new ContentMatch(
41-
$match[0],
42-
[
43-
'uid' => StringUtility::getUniqueId(),
44-
'iframeHash' => base64_encode($match[0]),
45-
'height' => !empty($match['height']) ? (MathUtility::canBeInterpretedAsInteger($match['height']) ? $match['height'] . 'px' : $match['height']) : 0,
46-
'width' => !empty($match['width']) ? (MathUtility::canBeInterpretedAsInteger($match['width']) ? $match['width'] . 'px' : $match['width']) : 0,
47-
]
48-
);
49-
},
35+
fn($match): \IchHabRecht\SocialGdpr\Handler\ContentMatch => new ContentMatch(
36+
$match[0],
37+
[
38+
'uid' => StringUtility::getUniqueId(),
39+
'iframeHash' => base64_encode($match[0]),
40+
'height' => !empty($match['height']) ? (MathUtility::canBeInterpretedAsInteger($match['height']) ? $match['height'] . 'px' : $match['height']) : 0,
41+
'width' => !empty($match['width']) ? (MathUtility::canBeInterpretedAsInteger($match['width']) ? $match['width'] . 'px' : $match['width']) : 0,
42+
]
43+
),
5044
$this->matches
5145
);
5246
}

Classes/Handler/OpenStreetMapHandler.php

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,13 @@ class OpenStreetMapHandler implements HandlerInterface
1919
/**
2020
* @var OpenStreetMapService
2121
*/
22-
protected $openStreetMapService;
22+
protected object $openStreetMapService;
2323

24-
public function __construct(OpenStreetMapService $openStreetMapService = null)
24+
public function __construct(?OpenStreetMapService $openStreetMapService = null)
2525
{
2626
$this->openStreetMapService = $openStreetMapService ?: GeneralUtility::makeInstance(OpenStreetMapService::class);
2727
}
2828

29-
/**
30-
* @param string $content
31-
* @return bool
32-
*/
3329
public function hasMatches(string $content): bool
3430
{
3531
preg_match_all(
@@ -48,18 +44,16 @@ public function hasMatches(string $content): bool
4844
public function getMatches(): array
4945
{
5046
return array_map(
51-
function ($match) {
52-
return new ContentMatch(
53-
$match[0],
54-
[
55-
'uid' => StringUtility::getUniqueId(),
56-
'iframeHash' => base64_encode($match[0]),
57-
'height' => !empty($match['height']) ? (MathUtility::canBeInterpretedAsInteger($match['height']) ? $match['height'] . 'px' : $match['height']) : 0,
58-
'width' => !empty($match['width']) ? (MathUtility::canBeInterpretedAsInteger($match['width']) ? $match['width'] . 'px' : $match['width']) : 0,
59-
'preview' => $this->openStreetMapService->getPreviewImage($match['bbox']),
60-
]
61-
);
62-
},
47+
fn($match): \IchHabRecht\SocialGdpr\Handler\ContentMatch => new ContentMatch(
48+
$match[0],
49+
[
50+
'uid' => StringUtility::getUniqueId(),
51+
'iframeHash' => base64_encode($match[0]),
52+
'height' => !empty($match['height']) ? (MathUtility::canBeInterpretedAsInteger($match['height']) ? $match['height'] . 'px' : $match['height']) : 0,
53+
'width' => !empty($match['width']) ? (MathUtility::canBeInterpretedAsInteger($match['width']) ? $match['width'] . 'px' : $match['width']) : 0,
54+
'preview' => $this->openStreetMapService->getPreviewImage($match['bbox']),
55+
]
56+
),
6357
$this->matches
6458
);
6559
}

Classes/Handler/VimeoHandler.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class VimeoHandler implements HandlerInterface
1919
/**
2020
* @var VimeoImageService
2121
*/
22-
protected $vimeoImageService;
22+
protected object $vimeoImageService;
2323

24-
public function __construct(VimeoImageService $vimeoImageService = null)
24+
public function __construct(?VimeoImageService $vimeoImageService = null)
2525
{
2626
$this->vimeoImageService = $vimeoImageService ?: GeneralUtility::makeInstance(VimeoImageService::class);
2727
}
@@ -41,19 +41,17 @@ public function hasMatches(string $content): bool
4141
public function getMatches(): array
4242
{
4343
return array_map(
44-
function ($match) {
45-
return new ContentMatch(
46-
$match[0],
47-
[
48-
'uid' => StringUtility::getUniqueId(),
49-
'id' => $match['id'],
50-
'iframeHash' => base64_encode($match[0]),
51-
'height' => !empty($match['height']) ? (MathUtility::canBeInterpretedAsInteger($match['height']) ? $match['height'] . 'px' : $match['height']) : 0,
52-
'width' => !empty($match['width']) ? (MathUtility::canBeInterpretedAsInteger($match['width']) ? $match['width'] . 'px' : $match['width']) : 0,
53-
'preview' => $this->vimeoImageService->getPreviewImage($match['id']),
54-
]
55-
);
56-
},
44+
fn($match): \IchHabRecht\SocialGdpr\Handler\ContentMatch => new ContentMatch(
45+
$match[0],
46+
[
47+
'uid' => StringUtility::getUniqueId(),
48+
'id' => $match['id'],
49+
'iframeHash' => base64_encode($match[0]),
50+
'height' => !empty($match['height']) ? (MathUtility::canBeInterpretedAsInteger($match['height']) ? $match['height'] . 'px' : $match['height']) : 0,
51+
'width' => !empty($match['width']) ? (MathUtility::canBeInterpretedAsInteger($match['width']) ? $match['width'] . 'px' : $match['width']) : 0,
52+
'preview' => $this->vimeoImageService->getPreviewImage($match['id']),
53+
]
54+
),
5755
$this->matches
5856
);
5957
}

0 commit comments

Comments
 (0)