1
|
|
|
<?php |
2
|
|
|
namespace DERHANSEN\SfEventMgt\ViewHelpers\Registration; |
3
|
|
|
|
4
|
|
|
/* |
5
|
|
|
* This file is part of the Extension "sf_event_mgt" for TYPO3 CMS. |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please read the |
8
|
|
|
* LICENSE.txt file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class IsRequiredFieldViewHelper |
15
|
|
|
*/ |
16
|
|
|
class IsRequiredFieldViewHelper extends AbstractConditionViewHelper |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* InitializeArguments |
20
|
|
|
*/ |
21
|
|
|
public function initializeArguments() |
22
|
|
|
{ |
23
|
|
|
$this->registerArgument('fieldname', 'string', 'A fieldname to be checked', false); |
24
|
|
|
$this->registerArgument('registrationField', 'object', 'A registration field record', false); |
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
|
|
|
* @return bool |
34
|
|
|
*/ |
35
|
|
|
protected static function evaluateCondition($arguments = null) |
36
|
|
|
{ |
37
|
|
|
$result = false; |
38
|
|
|
if (isset($arguments['fieldname']) && isset($arguments['settings'])) { |
39
|
|
|
$defaultRequiredFields = ['firstname', 'lastname', 'email']; |
40
|
|
|
$requiredFields = array_map('trim', explode(',', $arguments['settings']['registration']['requiredFields'])); |
41
|
|
|
$allRequiredFields = array_merge($requiredFields, $defaultRequiredFields); |
42
|
|
|
$result = in_array($arguments['fieldname'], $allRequiredFields); |
43
|
|
|
} |
44
|
|
|
if (isset($arguments['registrationField'])) { |
45
|
|
|
$result = $arguments['registrationField']->getRequired(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return $result; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return mixed |
53
|
|
|
*/ |
54
|
|
|
public function render() |
55
|
|
|
{ |
56
|
|
|
if (static::evaluateCondition($this->arguments)) { |
57
|
|
|
return $this->renderThenChild(); |
58
|
|
|
} |
59
|
|
|
return $this->renderElseChild(); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|