|
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\Registration; |
|
13
|
|
|
|
|
14
|
|
|
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class IsRequiredFieldViewHelper |
|
18
|
|
|
*/ |
|
19
|
|
|
class IsRequiredFieldViewHelper extends AbstractConditionViewHelper |
|
20
|
|
|
{ |
|
21
|
|
|
public function initializeArguments(): void |
|
22
|
|
|
{ |
|
23
|
|
|
$this->registerArgument('fieldname', 'string', 'A fieldname to be checked'); |
|
24
|
|
|
$this->registerArgument('registrationField', 'object', 'A registration field record'); |
|
25
|
|
|
$this->registerArgument('settings', 'array', 'The extension settings', true); |
|
26
|
|
|
parent::initializeArguments(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Evaluates the condition |
|
31
|
|
|
* |
|
32
|
|
|
* @param array|null $arguments |
|
33
|
|
|
*/ |
|
34
|
|
|
protected static function evaluateCondition($arguments = null): bool |
|
35
|
|
|
{ |
|
36
|
|
|
$result = false; |
|
37
|
|
|
if (isset($arguments['fieldname']) && isset($arguments['settings'])) { |
|
38
|
|
|
$defaultRequiredFields = ['firstname', 'lastname', 'email']; |
|
39
|
|
|
$requiredFields = array_map( |
|
40
|
|
|
'trim', |
|
41
|
|
|
explode(',', $arguments['settings']['registration']['requiredFields'] ?? '') |
|
42
|
|
|
); |
|
43
|
|
|
$allRequiredFields = array_merge($requiredFields, $defaultRequiredFields); |
|
44
|
|
|
$result = in_array($arguments['fieldname'], $allRequiredFields); |
|
45
|
|
|
} |
|
46
|
|
|
if (isset($arguments['registrationField'])) { |
|
47
|
|
|
$result = $arguments['registrationField']->getRequired(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
return $result; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @return mixed |
|
55
|
|
|
*/ |
|
56
|
|
|
public function render() |
|
57
|
|
|
{ |
|
58
|
|
|
if (static::evaluateCondition($this->arguments)) { |
|
59
|
|
|
return $this->renderThenChild(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return $this->renderElseChild(); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|