|
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\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
|
|
|
|
|
57
|
|
|
$this->metadata = ($identifier) |
|
58
|
|
|
? $this->metadataRepository->findOneByClassNameAndIdentifier($this->formObject->getClassName(), $identifier) |
|
59
|
|
|
: $this->metadataRepository->findOneByHash($formHash); |
|
60
|
|
|
|
|
61
|
|
|
if (false === $this->metadata instanceof FormMetadata) { |
|
62
|
|
|
$this->metadata = new FormMetadata( |
|
63
|
|
|
$formHash, |
|
64
|
|
|
$this->formObject->getClassName(), |
|
65
|
|
|
$this->getFormIdentifier(), |
|
66
|
|
|
new FormMetadataObject |
|
67
|
|
|
); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return $this->metadata; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return int|string |
|
76
|
|
|
*/ |
|
77
|
|
|
protected function getFormIdentifier() |
|
78
|
|
|
{ |
|
79
|
|
|
$identifier = null; |
|
80
|
|
|
|
|
81
|
|
|
if ($this->formObject->hasForm()) { |
|
82
|
|
|
$form = $this->formObject->getForm(); |
|
83
|
|
|
|
|
84
|
|
|
if ($form instanceof IdentifiableFormInterface) { |
|
85
|
|
|
$identifier = $form->getFormIdentifier(); |
|
86
|
|
|
} elseif ($form instanceof DomainObjectInterface |
|
87
|
|
|
&& null !== $form->getUid() |
|
88
|
|
|
) { |
|
89
|
|
|
$identifier = $form->getUid(); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
return $identifier; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @param FormMetadataRepository $metadataRepository |
|
98
|
|
|
*/ |
|
99
|
|
|
public function injectMetadataRepository(FormMetadataRepository $metadataRepository) |
|
100
|
|
|
{ |
|
101
|
|
|
$this->metadataRepository = $metadataRepository; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|