Skip to content

Commit 85739f4

Browse files
committed
[TASK] Make ext:form ConfigurationService stateless
Refactor ext:form ConfigurationService towards DI. The main FormFrontendController is refactored along the way. Both their test cases are turned into functional tests, to other tests are adapted slightly. Resolves: #104641 Releases: main Change-Id: I555ac4c4489eaf4b29e07240262bca362ac97dd6 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/85654 Tested-by: Anja Leichsenring <[email protected]> Tested-by: Christian Kuhn <[email protected]> Reviewed-by: Christian Kuhn <[email protected]> Reviewed-by: Anja Leichsenring <[email protected]> Tested-by: Stefan Bürk <[email protected]> Reviewed-by: Stefan Bürk <[email protected]> Tested-by: core-ci <[email protected]>
1 parent 9ed78fd commit 85739f4

File tree

7 files changed

+743
-1047
lines changed

7 files changed

+743
-1047
lines changed

Build/phpstan/phpstan-baseline.neon

-10
Original file line numberDiff line numberDiff line change
@@ -1210,16 +1210,6 @@ parameters:
12101210
count: 5
12111211
path: ../../typo3/sysext/form/Classes/Controller/FormManagerController.php
12121212

1213-
-
1214-
message: "#^Call to sprintf contains 4 placeholders, 5 values given\\.$#"
1215-
count: 1
1216-
path: ../../typo3/sysext/form/Classes/Domain/Configuration/ConfigurationService.php
1217-
1218-
-
1219-
message: "#^Variable \\$formElements on left side of \\?\\? always exists and is not nullable\\.$#"
1220-
count: 2
1221-
path: ../../typo3/sysext/form/Classes/Domain/Configuration/ConfigurationService.php
1222-
12231213
-
12241214
message: "#^Result of && is always false\\.$#"
12251215
count: 1

typo3/sysext/form/Classes/Controller/FormFrontendController.php

+13-38
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,12 @@
3939
*/
4040
class FormFrontendController extends ActionController
4141
{
42-
/**
43-
* @var \TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManagerInterface
44-
*/
45-
protected $formPersistenceManager;
46-
47-
/**
48-
* @internal
49-
*/
50-
public function injectFormPersistenceManager(FormPersistenceManagerInterface $formPersistenceManager)
51-
{
52-
$this->formPersistenceManager = $formPersistenceManager;
53-
}
42+
public function __construct(
43+
protected readonly ConfigurationService $configurationService,
44+
protected readonly FormPersistenceManagerInterface $formPersistenceManager,
45+
protected readonly FlexFormService $flexFormService,
46+
protected readonly FlexFormTools $flexFormTools,
47+
) {}
5448

5549
/**
5650
* Take the form which should be rendered from the plugin settings
@@ -72,7 +66,6 @@ public function renderAction(): ResponseInterface
7266
$formDefinition['identifier'] .= '-' . ($this->request->getAttribute('currentContentObject')?->data['uid'] ?? '');
7367
}
7468
$this->view->assign('formConfiguration', $formDefinition);
75-
7669
return $this->htmlResponse();
7770
}
7871

@@ -94,22 +87,16 @@ public function performAction(): ResponseInterface
9487
protected function overrideByFlexFormSettings(array $formDefinition): array
9588
{
9689
$flexFormData = GeneralUtility::xml2array($this->request->getAttribute('currentContentObject')?->data['pi_flexform'] ?? '');
97-
9890
if (!is_array($flexFormData)) {
9991
return $formDefinition;
10092
}
101-
10293
if (isset($formDefinition['finishers'])) {
10394
$prototypeName = $formDefinition['prototypeName'] ?? 'standard';
104-
$configurationService = GeneralUtility::makeInstance(ConfigurationService::class);
105-
$prototypeConfiguration = $configurationService->getPrototypeConfiguration($prototypeName);
106-
95+
$prototypeConfiguration = $this->configurationService->getPrototypeConfiguration($prototypeName);
10796
foreach ($formDefinition['finishers'] as $index => $formFinisherDefinition) {
10897
$finisherIdentifier = $formFinisherDefinition['identifier'];
109-
11098
$sheetIdentifier = $this->getFlexformSheetIdentifier($formDefinition, $prototypeName, $finisherIdentifier);
11199
$flexFormSheetSettings = $this->getFlexFormSettingsFromSheet($flexFormData, $sheetIdentifier);
112-
113100
if (($this->settings['overrideFinishers'] ?? false) && isset($flexFormSheetSettings['finishers'][$finisherIdentifier])) {
114101
$prototypeFinisherDefinition = $prototypeConfiguration['finishersDefinition'][$finisherIdentifier] ?? [];
115102
$converterDto = GeneralUtility::makeInstance(
@@ -119,7 +106,6 @@ protected function overrideByFlexFormSettings(array $formDefinition): array
119106
$finisherIdentifier,
120107
$flexFormSheetSettings
121108
);
122-
123109
// Iterate over all `prototypes.<prototypeName>.finishersDefinition.<finisherIdentifier>.FormEngine.elements` values
124110
GeneralUtility::makeInstance(ArrayProcessor::class, $prototypeFinisherDefinition['FormEngine']['elements'])->forEach(
125111
GeneralUtility::makeInstance(
@@ -129,19 +115,15 @@ protected function overrideByFlexFormSettings(array $formDefinition): array
129115
GeneralUtility::makeInstance(FinisherOptionsFlexFormOverridesConverter::class, $converterDto)
130116
)
131117
);
132-
133118
$formDefinition['finishers'][$index] = $converterDto->getFinisherDefinition();
134119
}
135120
}
136121
}
137122
return $formDefinition;
138123
}
139124

140-
protected function getFlexformSheetIdentifier(
141-
array $formDefinition,
142-
string $prototypeName,
143-
string $finisherIdentifier
144-
): string {
125+
protected function getFlexformSheetIdentifier(array $formDefinition, string $prototypeName, string $finisherIdentifier): string
126+
{
145127
return md5(
146128
implode('', [
147129
$formDefinition['persistenceIdentifier'],
@@ -152,10 +134,8 @@ protected function getFlexformSheetIdentifier(
152134
);
153135
}
154136

155-
protected function getFlexFormSettingsFromSheet(
156-
array $flexForm,
157-
string $sheetIdentifier
158-
): array {
137+
protected function getFlexFormSettingsFromSheet(array $flexForm, string $sheetIdentifier): array
138+
{
159139
$sheetData = [];
160140
$sheetData['data'] = array_filter(
161141
$flexForm['data'] ?? [],
@@ -164,15 +144,10 @@ static function ($key) use ($sheetIdentifier) {
164144
},
165145
ARRAY_FILTER_USE_KEY
166146
);
167-
168147
if (empty($sheetData['data'])) {
169148
return [];
170149
}
171-
172-
$flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
173-
$flexFormTools = GeneralUtility::makeInstance(FlexFormTools::class);
174-
175-
$sheetDataXml = $flexFormTools->flexArray2Xml($sheetData);
176-
return $flexFormService->convertFlexFormContentToArray($sheetDataXml)['settings'] ?? [];
150+
$sheetDataXml = $this->flexFormTools->flexArray2Xml($sheetData);
151+
return $this->flexFormService->convertFlexFormContentToArray($sheetDataXml)['settings'] ?? [];
177152
}
178153
}

0 commit comments

Comments
 (0)