|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the TYPO3 CMS project. |
|
7
|
|
|
* |
|
8
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
9
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
10
|
|
|
* of the License, or any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* For the full copyright and license information, please read the |
|
13
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
14
|
|
|
* |
|
15
|
|
|
* The TYPO3 project - inspiring people to share! |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace TYPO3\CMS\Form\Domain\Configuration\FlexformConfiguration\Processors; |
|
19
|
|
|
|
|
20
|
|
|
use TYPO3\CMS\Core\Localization\LanguageService; |
|
21
|
|
|
use TYPO3\CMS\Core\Utility\ArrayUtility; |
|
22
|
|
|
use TYPO3\CMS\Core\Utility\Exception\MissingArrayPathException; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Generate a FlexForm element for a finisher option |
|
26
|
|
|
* |
|
27
|
|
|
* @internal |
|
28
|
|
|
*/ |
|
29
|
|
|
class FinisherOptionGenerator extends AbstractProcessor |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* @param string $_ unused in this context |
|
33
|
|
|
* @param mixed $__ unused in this context |
|
34
|
|
|
* @param array $matches the expression matches from the ArrayProcessor - for example matches of ^(.*)\.config\.type$ |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __invoke(string $_, $__, array $matches) |
|
37
|
|
|
{ |
|
38
|
|
|
[, $optionKey] = $matches; |
|
39
|
|
|
|
|
40
|
|
|
$finisherIdentifier = $this->converterDto->getFinisherIdentifier(); |
|
41
|
|
|
$finisherDefinitionFromSetup = $this->converterDto->getFinisherDefinitionFromSetup(); |
|
42
|
|
|
$finisherDefinitionFromFormDefinition = $this->converterDto->getFinisherDefinitionFromFormDefinition(); |
|
43
|
|
|
|
|
44
|
|
|
try { |
|
45
|
|
|
$elementConfiguration = ArrayUtility::getValueByPath( |
|
46
|
|
|
$finisherDefinitionFromSetup['FormEngine']['elements'], |
|
47
|
|
|
$optionKey, |
|
48
|
|
|
'.' |
|
49
|
|
|
); |
|
50
|
|
|
} catch (MissingArrayPathException $exception) { |
|
51
|
|
|
return; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
// use the option value from the ext:form setup from the current finisher as default value |
|
55
|
|
|
try { |
|
56
|
|
|
$optionValue = ArrayUtility::getValueByPath( |
|
|
|
|
|
|
57
|
|
|
$finisherDefinitionFromSetup, |
|
58
|
|
|
sprintf('options.%s', $optionKey), |
|
59
|
|
|
'.' |
|
60
|
|
|
); |
|
61
|
|
|
} catch (MissingArrayPathException $exception) { |
|
62
|
|
|
$optionValue = null; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
// use the option value from the form definition from the current finisher (if exists) as default value |
|
66
|
|
|
try { |
|
67
|
|
|
$optionValue = ArrayUtility::getValueByPath( |
|
68
|
|
|
$finisherDefinitionFromFormDefinition, |
|
69
|
|
|
sprintf('options.%s', $optionKey), |
|
70
|
|
|
'.' |
|
71
|
|
|
); |
|
72
|
|
|
} catch (MissingArrayPathException $exception) { |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
$languageService = $this->getLanguageService(); |
|
76
|
|
|
if (empty($optionValue)) { |
|
77
|
|
|
$elementConfiguration['label'] .= sprintf(' (%s: "%s")', $languageService->getLL('default'), $languageService->getLL('empty')); |
|
78
|
|
|
} else { |
|
79
|
|
|
$elementConfiguration['label'] .= sprintf(' (%s: "' . $optionValue . '")', $languageService->getLL('default')); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
if (isset($elementConfiguration['config'])) { |
|
83
|
|
|
$elementConfiguration['config']['default'] = $optionValue; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
$sheetElements = $this->converterDto->getResult(); |
|
87
|
|
|
$sheetElements['settings.finishers.' . $finisherIdentifier . '.' . $optionKey]['TCEforms'] = $elementConfiguration; |
|
88
|
|
|
|
|
89
|
|
|
$this->converterDto->setResult($sheetElements); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
protected function getLanguageService(): LanguageService |
|
93
|
|
|
{ |
|
94
|
|
|
return $GLOBALS['LANG']; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|