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\Definition\Condition; |
15
|
|
|
|
16
|
|
|
use Romm\ConfigurationObject\Service\Items\MixedTypes\MixedTypesInterface; |
17
|
|
|
use Romm\ConfigurationObject\Service\Items\MixedTypes\MixedTypesResolver; |
18
|
|
|
use Romm\Formz\Condition\ConditionFactory; |
19
|
|
|
use TYPO3\CMS\Extbase\Error\Error; |
20
|
|
|
|
21
|
|
|
class ConditionItemResolver implements MixedTypesInterface |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Because this class implements `MixedTypeInterface`, this function needs |
26
|
|
|
* to be implemented. |
27
|
|
|
* |
28
|
|
|
* It will allow to fill properly the properties of type |
29
|
|
|
* `AbstractConditionItem` by returning the real type of the condition. |
30
|
|
|
* |
31
|
|
|
* The property `type` must be present in the resolver data, and contain one |
32
|
|
|
* of the values of `AbstractConditionItem::$types`. |
33
|
|
|
* |
34
|
|
|
* @param MixedTypesResolver $resolver |
35
|
|
|
*/ |
36
|
|
|
final public static function getInstanceClassName(MixedTypesResolver $resolver) |
37
|
|
|
{ |
38
|
|
|
$conditionFactory = ConditionFactory::get(); |
39
|
|
|
$data = $resolver->getData(); |
40
|
|
|
$conditionName = (true === is_array($data) && true === isset($data['type'])) |
41
|
|
|
? $data['type'] |
42
|
|
|
: null; |
43
|
|
|
|
44
|
|
|
if (false === $conditionFactory->hasCondition($conditionName)) { |
45
|
|
|
$error = new Error( |
46
|
|
|
'No condition was found (type: "' . $data['type'] . '").', |
47
|
|
|
1471809847 |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
$resolver->addError($error); |
51
|
|
|
} else { |
52
|
|
|
$resolver->setObjectType($conditionFactory->getCondition($conditionName)); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|