Completed
Push — wip/steps ( d74e9e...854d85 )
by Romain
02:42
created

injectSignalSlotDispatcher()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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
use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
22
23
/**
24
 * Default form object builder.
25
 *
26
 * It fetches the form configuration array from TypoScript, and automatically
27
 * inserts the class properties of the form in the properties of the form
28
 * object.
29
 */
30
class DefaultFormObjectBuilder extends AbstractFormObjectBuilder
31
{
32
    const FORM_DEFINITION_BUILT = 'formDefinitionBuilt';
33
34
    /**
35
     * @var Dispatcher
36
     */
37
    protected $signalSlotDispatcher;
38
39
    /**
40
     * @see DefaultFormObjectBuilder
41
     */
42
    public function process()
43
    {
44
        $this->insertObjectProperties();
45
    }
46
47
    /**
48
     * @return FormDefinitionObject
49
     */
50
    protected function getFormDefinitionObject()
51
    {
52
        $configurationArray = TypoScriptService::get()->getFormConfiguration($this->className);
53
        $configurationObject = ConfigurationObjectFactory::convert(FormDefinition::class, $configurationArray);
54
55
        /** @var FormDefinitionObject $formDefinitionObject */
56
        $formDefinitionObject = GeneralUtility::makeInstance(
57
            FormDefinitionObject::class,
58
            $configurationObject->getObject(true),
59
            $configurationObject->getValidationResult()
60
        );
61
62
        $this->signalSlotDispatcher->dispatch(
63
            self::class,
64
            self::FORM_DEFINITION_BUILT,
65
            [$this->className, $formDefinitionObject]
66
        );
67
68
        return $formDefinitionObject;
69
    }
70
71
    /**
72
     * Will insert all the accessible properties of the form class in the form
73
     * object.
74
     */
75
    protected function insertObjectProperties()
76
    {
77
        foreach ($this->static->getProperties() as $propertyName) {
78
            if (false === $this->static->getDefinition()->hasField($propertyName)) {
79
                $this->static->getDefinition()->addField($propertyName);
80
            }
81
        }
82
    }
83
84
    /**
85
     * @return FormDefinition
86
     */
87
    public function getFormDefinition()
88
    {
89
        return null;
90
    }
91
92
    /**
93
     * @param Dispatcher $signalSlotDispatcher
94
     */
95
    public function injectSignalSlotDispatcher(Dispatcher $signalSlotDispatcher)
96
    {
97
        $this->signalSlotDispatcher = $signalSlotDispatcher;
98
    }
99
}
100