1
|
|
|
<?php |
2
|
|
|
namespace DERHANSEN\SfEventMgt\ViewHelpers\Registration\Field; |
3
|
|
|
|
4
|
|
|
/* |
5
|
|
|
* This file is part of the TYPO3 CMS project. |
6
|
|
|
* |
7
|
|
|
* It is free software; you can redistribute it and/or modify it under |
8
|
|
|
* the terms of the GNU General Public License, either version 2 |
9
|
|
|
* of the License, or any later version. |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please read the |
12
|
|
|
* LICENSE.txt file that was distributed with this source code. |
13
|
|
|
* |
14
|
|
|
* The TYPO3 project - inspiring people to share! |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* PrefillField ViewHelper for registration fields |
21
|
|
|
* |
22
|
|
|
* @author Torben Hansen <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class PrefillFieldViewHelper extends AbstractViewHelper |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Returns a string to be used as prefill value for the given registration field (type=input). If the form |
28
|
|
|
* has already been submitted, the submitted value for the field is returned. |
29
|
|
|
* |
30
|
|
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Registration\Field $registrationField |
31
|
|
|
* @return string |
32
|
|
|
*/ |
33
|
|
|
public function render($registrationField) |
34
|
|
|
{ |
35
|
|
|
// If mapping errors occured for form, return value that has been submitted |
36
|
|
|
$originalRequest = $this->controllerContext->getRequest()->getOriginalRequest(); |
37
|
|
|
if ($originalRequest) { |
38
|
|
|
return $this->getFieldValueFromArguments($originalRequest->getArguments(), $registrationField->getUid()); |
39
|
|
|
} else { |
40
|
|
|
return $registrationField->getDefaultValue(); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Returns the submitted value for the given field uid |
46
|
|
|
* |
47
|
|
|
* @param array $submittedValues |
48
|
|
|
* @param int $fieldUid |
49
|
|
|
* @return string |
50
|
|
|
*/ |
51
|
|
|
protected function getFieldValueFromArguments($submittedValues, $fieldUid) |
52
|
|
|
{ |
53
|
|
|
$result = ''; |
54
|
|
|
foreach ($submittedValues['registration']['fieldValues'] as $fieldValue) { |
55
|
|
|
if ((int)$fieldValue['field'] === $fieldUid) { |
56
|
|
|
$result = $fieldValue['value']; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
return $result; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|