Completed
Push — master ( 7cb6b5...5849c4 )
by
unknown
02:40
created

FieldIsEmptyCondition::getFieldName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/*
3
 * 2016 Romain CANON <[email protected]>
4
 *
5
 * This file is part of the TYPO3 Formz project.
6
 * It is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU General Public License, either
8
 * version 3 of the License, or any later version.
9
 *
10
 * For the full copyright and license information, see:
11
 * http://www.gnu.org/licenses/gpl-3.0.html
12
 */
13
14
namespace Romm\Formz\Condition\Items;
15
16
use Romm\Formz\AssetHandler\Html\DataAttributesAssetHandler;
17
use Romm\Formz\Form\FormInterface;
18
use Romm\Formz\Validation\Validator\Form\AbstractFormValidator;
19
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;
20
21
/**
22
 * This condition will match when a field is valid (its validation returned no
23
 * error).
24
 */
25
class FieldIsEmptyCondition extends AbstractConditionItem
26
{
27
28
    const CONDITION_NAME = 'fieldIsEmpty';
29
30
    /**
31
     * @inheritdoc
32
     * @var array
33
     */
34
    protected static $javaScriptFiles = [
35
        'EXT:formz/Resources/Public/JavaScript/Conditions/Formz.Condition.FieldIsEmpty.js'
36
    ];
37
38
    /**
39
     * @var string
40
     * @validate NotEmpty
41
     */
42
    protected $fieldName;
43
44
    /**
45
     * @inheritdoc
46
     */
47
    public function getCssResult()
48
    {
49
        return '[' . DataAttributesAssetHandler::getFieldDataValidKey($this->fieldName) . '=""]';
50
    }
51
52
    /**
53
     * @inheritdoc
54
     */
55
    public function getJavaScriptResult()
56
    {
57
        return $this->getDefaultJavaScriptCall(['fieldName' => $this->fieldName]);
58
    }
59
60
    /**
61
     * @inheritdoc
62
     */
63
    public function getPhpResult(FormInterface $form, AbstractFormValidator $formValidator)
64
    {
65
        $value = ObjectAccess::getProperty($form, $this->fieldName);
66
67
        return empty($value);
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    public function getFieldName()
74
    {
75
        return $this->fieldName;
76
    }
77
}
78