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