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\Configuration\View\Classes; |
15
|
|
|
|
16
|
|
|
use Romm\ConfigurationObject\Service\Items\DataPreProcessor\DataPreProcessor; |
17
|
|
|
use Romm\ConfigurationObject\Service\Items\DataPreProcessor\DataPreProcessorInterface; |
18
|
|
|
use Romm\Formz\Configuration\AbstractFormzConfiguration; |
19
|
|
|
|
20
|
|
|
class ViewClass extends AbstractFormzConfiguration implements DataPreProcessorInterface |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var array |
25
|
|
|
*/ |
26
|
|
|
protected $items = []; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* This function is called before the TypoScript data is injected in this |
30
|
|
|
* class. We use it to put all the array data in the key `items`, so it can |
31
|
|
|
* be properly injected in the `$items` property. |
32
|
|
|
* |
33
|
|
|
* @param DataPreProcessor $processor |
34
|
|
|
*/ |
35
|
|
|
public static function dataPreProcessor(DataPreProcessor $processor) |
36
|
|
|
{ |
37
|
|
|
$finalData = []; |
38
|
|
|
$data = $processor->getData(); |
39
|
|
|
|
40
|
|
|
foreach ($data as $key => $value) { |
41
|
|
|
$finalData[$key] = (string)$value; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$processor->setData(['items' => $finalData]); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return array |
49
|
|
|
*/ |
50
|
|
|
public function getItems() |
51
|
|
|
{ |
52
|
|
|
return $this->items; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param string $itemName |
57
|
|
|
* @return bool |
58
|
|
|
*/ |
59
|
|
|
public function hasItem($itemName) |
60
|
|
|
{ |
61
|
|
|
return true === isset($this->items[$itemName]); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param string $itemName |
66
|
|
|
* @return array|null |
67
|
|
|
*/ |
68
|
|
|
public function getItem($itemName) |
69
|
|
|
{ |
70
|
|
|
return (true === isset($this->items[$itemName])) |
71
|
|
|
? $this->items[$itemName] |
72
|
|
|
: null; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param string $itemName |
77
|
|
|
* @param string $value |
78
|
|
|
*/ |
79
|
|
|
public function addItem($itemName, $value) |
80
|
|
|
{ |
81
|
|
|
$this->items[$itemName] = $value; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|