|
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
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.