|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Extension "sf_event_mgt" for TYPO3 CMS. |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please read the |
|
7
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace DERHANSEN\SfEventMgt\ViewHelpers\Registration\Field; |
|
11
|
|
|
|
|
12
|
|
|
use DERHANSEN\SfEventMgt\Domain\Model\Registration\Field; |
|
13
|
|
|
use DERHANSEN\SfEventMgt\ViewHelpers\AbstractPrefillViewHelper; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* PrefillField ViewHelper for registration fields |
|
17
|
|
|
*/ |
|
18
|
|
|
class PrefillFieldViewHelper extends AbstractPrefillViewHelper |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* Initialize arguments |
|
22
|
|
|
*/ |
|
23
|
|
|
public function initializeArguments() |
|
24
|
|
|
{ |
|
25
|
|
|
parent::initializeArguments(); |
|
26
|
|
|
$this->registerArgument('registrationField', 'object', 'The registrationField object', true); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Returns a string to be used as prefill value for the given registration field (type=input). If the form |
|
31
|
|
|
* has already been submitted, the submitted value for the field is returned. |
|
32
|
|
|
* |
|
33
|
|
|
* @return string |
|
34
|
|
|
*/ |
|
35
|
|
|
public function render() |
|
36
|
|
|
{ |
|
37
|
|
|
/** @var Field $registrationField */ |
|
38
|
|
|
$registrationField = $this->arguments['registrationField']; |
|
39
|
|
|
|
|
40
|
|
|
// If mapping errors occured for form, return value that has been submitted from POST data |
|
41
|
|
|
$originalRequest = $this->renderingContext->getRequest()->getOriginalRequest(); |
|
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
if ($originalRequest) { |
|
44
|
|
|
$registrationData = $originalRequest->getParsedBody()[$this->getPluginNamespace($originalRequest)] ?? []; |
|
45
|
|
|
return $this->getFieldValueFromSubmittedData($registrationData, $registrationField->getUid()); |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
return $registrationField->getDefaultValue(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Returns the submitted value for the given field uid |
|
53
|
|
|
* |
|
54
|
|
|
* @param array $submittedData |
|
55
|
|
|
* @param int $fieldUid |
|
56
|
|
|
* @return string |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function getFieldValueFromSubmittedData(array $submittedData, int $fieldUid): string |
|
59
|
|
|
{ |
|
60
|
|
|
$result = ''; |
|
61
|
|
|
foreach ($submittedData['registration']['fields'] ?? [] as $submittedFieldUid => $fieldValue) { |
|
62
|
|
|
if ((int)$submittedFieldUid === $fieldUid) { |
|
63
|
|
|
$result = $fieldValue; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return $result; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|