Completed
Push — feature/method-get-properties ( 045265 )
by Romain
02:45
created

DefaultFormObjectBuilder::insertObjectProperties()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 3
nop 0
1
<?php
2
/*
3
 * 2017 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\Form\FormObject\Builder;
15
16
use Romm\ConfigurationObject\ConfigurationObjectFactory;
17
use Romm\Formz\Form\Definition\FormDefinition;
18
use Romm\Formz\Form\FormObject\Definition\FormDefinitionObject;
19
use Romm\Formz\Service\TypoScriptService;
20
use TYPO3\CMS\Core\Utility\GeneralUtility;
21
22
/**
23
 * Default form object builder.
24
 *
25
 * It fetches the form configuration array from TypoScript, and automatically
26
 * inserts the class properties of the form in the properties of the form
27
 * object.
28
 */
29
class DefaultFormObjectBuilder extends AbstractFormObjectBuilder
30
{
31
    /**
32
     * @see DefaultFormObjectBuilder
33
     */
34
    public function process()
35
    {
36
        $this->insertObjectProperties();
37
    }
38
39
    /**
40
     * @return FormDefinitionObject
41
     */
42
    protected function getFormDefinitionObject()
43
    {
44
        $configurationArray = TypoScriptService::get()->getFormConfiguration($this->className);
45
        $configurationObject = ConfigurationObjectFactory::convert(FormDefinition::class, $configurationArray);
46
47
        /** @var FormDefinitionObject $formDefinitionObject */
48
        $formDefinitionObject = GeneralUtility::makeInstance(
49
            FormDefinitionObject::class,
50
            $configurationObject->getObject(true),
51
            $configurationObject->getValidationResult()
52
        );
53
54
        return $formDefinitionObject;
55
    }
56
57
    /**
58
     * Will insert all the accessible properties of the form class in the form
59
     * object.
60
     */
61
    protected function insertObjectProperties()
62
    {
63
        foreach ($this->static->getProperties() as $propertyName) {
64
            if (false === $this->static->getDefinition()->hasField($propertyName)) {
65
                $this->static->getDefinition()->addField($propertyName);
66
            }
67
        }
68
    }
69
70
    /**
71
     * @return FormDefinition
72
     */
73
    public function getFormDefinition()
74
    {
75
        return null;
76
    }
77
}
78