1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Extension "sf_event_mgt" for TYPO3 CMS. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the |
9
|
|
|
* LICENSE.txt file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace DERHANSEN\SfEventMgt\ViewHelpers; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Prefill ViewHelper |
16
|
|
|
*/ |
17
|
|
|
class PrefillViewHelper extends AbstractPrefillViewHelper |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Initialize arguments |
21
|
|
|
*/ |
22
|
|
|
public function initializeArguments() |
23
|
|
|
{ |
24
|
|
|
parent::initializeArguments(); |
25
|
|
|
$this->registerArgument('fieldname', 'string', 'FieldName', true); |
26
|
|
|
$this->registerArgument('prefillSettings', 'array', 'PrefillSettings', false, []); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* If the current field is available in POST data of the current request, return the value, otherwise |
31
|
|
|
* a property from fe_user (if logged in and if the given field is configured to be prefilled) is returned. |
32
|
|
|
* |
33
|
|
|
* @return string |
34
|
|
|
*/ |
35
|
|
|
public function render(): string |
36
|
16 |
|
{ |
37
|
|
|
$fieldname = $this->arguments['fieldname']; |
38
|
16 |
|
$prefillSettings = $this->arguments['prefillSettings']; |
39
|
16 |
|
|
40
|
2 |
|
$request = $this->renderingContext->getRequest(); |
|
|
|
|
41
|
|
|
$registrationData = $request->getParsedBody()[$this->getPluginNamespace($request)] ?? []; |
42
|
14 |
|
if (isset($registrationData['registration'][$fieldname])) { |
43
|
8 |
|
return $registrationData['registration'][$fieldname]; |
44
|
14 |
|
} |
45
|
8 |
|
|
46
|
|
|
if (!isset($GLOBALS['TSFE']) || !$GLOBALS['TSFE']->fe_user->user || empty($prefillSettings) || |
47
|
|
|
!array_key_exists($fieldname, $prefillSettings) |
48
|
6 |
|
) { |
49
|
6 |
|
return ''; |
50
|
2 |
|
} |
51
|
2 |
|
|
52
|
|
|
return (string)($GLOBALS['TSFE']->fe_user->user[$prefillSettings[$fieldname]]); |
53
|
4 |
|
} |
54
|
|
|
} |
55
|
|
|
|