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\Formz\Core\Core; |
17
|
|
|
use Romm\Formz\Form\Definition\FormDefinition; |
18
|
|
|
use Romm\Formz\Form\FormObject\Definition\FormDefinitionObject; |
19
|
|
|
use Romm\Formz\Form\FormObject\FormObjectStatic; |
20
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
21
|
|
|
|
22
|
|
|
abstract class AbstractFormObjectBuilder implements FormObjectBuilderInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $className; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var FormObjectStatic |
31
|
|
|
*/ |
32
|
|
|
protected $static; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param string $className |
36
|
|
|
* @return FormObjectStatic |
37
|
|
|
*/ |
38
|
|
|
public function getStaticInstance($className) |
39
|
|
|
{ |
40
|
|
|
$this->className = $className; |
41
|
|
|
|
42
|
|
|
$formDefinitionObject = $this->getFormDefinitionObject(); |
43
|
|
|
|
44
|
|
|
$this->static = Core::instantiate( |
45
|
|
|
FormObjectStatic::class, |
46
|
|
|
$this->className, |
47
|
|
|
$formDefinitionObject |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
$this->process(); |
51
|
|
|
|
52
|
|
|
// $middleware = $this->static->getDefinition()->addMiddleware( |
53
|
|
|
// 'test', |
54
|
|
|
// \Romm\FormzExample\Middlewares\TestMiddleware::class, |
55
|
|
|
// function (\Romm\FormzExample\Middlewares\Options\TestOptions $options) { |
56
|
|
|
// $options->setFoo('pouet'); |
57
|
|
|
// } |
58
|
|
|
// ); |
59
|
|
|
// debug($middleware); |
60
|
|
|
// die('!!'); |
61
|
|
|
|
62
|
|
|
$formDefinitionObject->refreshValidationResult(); |
63
|
|
|
|
64
|
|
|
return $this->static; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return FormDefinitionObject |
69
|
|
|
*/ |
70
|
|
|
protected function getFormDefinitionObject() |
71
|
|
|
{ |
72
|
|
|
/** @var FormDefinitionObject $formDefinitionObject */ |
73
|
|
|
$formDefinitionObject = GeneralUtility::makeInstance(FormDefinitionObject::class, $this->getFormDefinition()); |
74
|
|
|
|
75
|
|
|
return $formDefinitionObject; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Override this function in child classes to implement custom processes. |
80
|
|
|
*/ |
81
|
|
|
protected function process() |
82
|
|
|
{ |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Must return the form definition of the form class. |
87
|
|
|
* |
88
|
|
|
* @return FormDefinition |
89
|
|
|
*/ |
90
|
|
|
abstract public function getFormDefinition(); |
91
|
|
|
} |
92
|
|
|
|