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\Service; |
15
|
|
|
|
16
|
|
|
use Romm\Formz\Domain\Model\DataObject\FormMetadataObject; |
17
|
|
|
use Romm\Formz\Domain\Model\FormMetadata; |
18
|
|
|
use Romm\Formz\Domain\Repository\FormMetadataRepository; |
19
|
|
|
use Romm\Formz\Form\FormObject\FormObject; |
20
|
|
|
use Romm\Formz\Form\IdentifiableFormInterface; |
21
|
|
|
use TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface; |
22
|
|
|
|
23
|
|
|
class FormObjectMetadata |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var FormObject |
27
|
|
|
*/ |
28
|
|
|
protected $formObject; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var FormMetadata |
32
|
|
|
*/ |
33
|
|
|
protected $metadata; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var FormMetadataRepository |
37
|
|
|
*/ |
38
|
|
|
protected $metadataRepository; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param FormObject $formObject |
42
|
|
|
*/ |
43
|
|
|
public function __construct(FormObject $formObject) |
44
|
|
|
{ |
45
|
|
|
$this->formObject = $formObject; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return FormMetadata |
50
|
|
|
*/ |
51
|
|
|
public function getMetadata() |
52
|
|
|
{ |
53
|
|
|
if (null === $this->metadata) { |
54
|
|
|
$formHash = $this->formObject->getFormHash(); |
55
|
|
|
$identifier = $this->getFormIdentifier(); |
56
|
|
|
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($identifier, '$identifier'); |
57
|
|
|
|
58
|
|
|
$this->metadata = ($identifier) |
59
|
|
|
? $this->metadataRepository->findOneByClassNameAndIdentifier($this->formObject->getClassName(), $identifier) |
60
|
|
|
: $this->metadataRepository->findOneByHash($formHash); |
61
|
|
|
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($this->metadata, '$this->metadata'); |
62
|
|
|
if (false === $this->metadata instanceof FormMetadata) { |
63
|
|
|
$this->metadata = new FormMetadata( |
64
|
|
|
$formHash, |
65
|
|
|
$this->formObject->getClassName(), |
66
|
|
|
$this->getFormIdentifier(), |
67
|
|
|
new FormMetadataObject |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $this->metadata; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @todo |
77
|
|
|
*/ |
78
|
|
|
public function unsetMetadata() |
79
|
|
|
{ |
80
|
|
|
$this->metadata = null; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return int|string |
85
|
|
|
*/ |
86
|
|
|
protected function getFormIdentifier() |
87
|
|
|
{ |
88
|
|
|
$identifier = null; |
89
|
|
|
|
90
|
|
|
if ($this->formObject->hasForm()) { |
91
|
|
|
$form = $this->formObject->getForm(); |
92
|
|
|
|
93
|
|
|
if ($form instanceof IdentifiableFormInterface) { |
94
|
|
|
$identifier = $form->getFormIdentifier(); |
95
|
|
|
} elseif ($form instanceof DomainObjectInterface |
96
|
|
|
&& null !== $form->getUid() |
97
|
|
|
) { |
98
|
|
|
$identifier = $form->getUid(); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
return $identifier; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param FormMetadataRepository $metadataRepository |
107
|
|
|
*/ |
108
|
|
|
public function injectMetadataRepository(FormMetadataRepository $metadataRepository) |
109
|
|
|
{ |
110
|
|
|
$this->metadataRepository = $metadataRepository; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|