Completed
Push — development ( 71fb94...8a17e5 )
by Torben
02:20
created

IsRequiredFieldViewHelper::evaluateCondition()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
rs 9.2
cc 4
eloc 10
nc 4
nop 1
1
<?php
2
3
namespace DERHANSEN\SfEventMgt\ViewHelpers\Registration;
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
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
13
use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
14
15
class IsRequiredFieldViewHelper extends AbstractConditionViewHelper implements CompilableInterface
16
{
17
    /**
18
     * InitializeArguments
19
     */
20
    public function initializeArguments()
21
    {
22
        $this->registerArgument('fieldname', 'string', 'A fieldname to be checked', false);
23
        $this->registerArgument('registrationField', 'object', 'A registration field record', false);
24
        $this->registerArgument('settings', 'array', 'The extension settings', true);
25
        parent::initializeArguments();
26
    }
27
28
    /**
29
     * Evaluates the condition
30
     *
31
     * @param array|null $arguments
32
     * @return bool
33
     */
34
    protected static function evaluateCondition($arguments = null)
35
    {
36
        $result = false;
37
        if (isset($arguments['fieldname']) && isset($arguments['settings'])) {
38
            $defaultRequiredFields = ['firstname', 'lastname', 'email'];
39
            $requiredFields = array_map('trim', explode(',', $arguments['settings']['registration']['requiredFields']));
40
            $allRequiredFields = array_merge($requiredFields, $defaultRequiredFields);
41
            $result = in_array($arguments['fieldname'], $allRequiredFields);
42
        }
43
        if (isset($arguments['registrationField'])) {
44
            $result = $arguments['registrationField']->getRequired();
45
        }
46
        return $result;
47
    }
48
}
49