|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* AbstractField class file |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Graviton\DocumentBundle\DependencyInjection\Compiler\Utils; |
|
7
|
|
|
|
|
8
|
|
|
use Symfony\Component\Form\FormConfigBuilder; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Base document field |
|
12
|
|
|
* |
|
13
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
|
14
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
15
|
|
|
* @link http://swisscom.ch |
|
16
|
|
|
*/ |
|
17
|
|
|
class AbstractField |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
private $fieldName; |
|
23
|
|
|
/** |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
private $exposedName; |
|
27
|
|
|
/** |
|
28
|
|
|
* @var bool |
|
29
|
|
|
*/ |
|
30
|
|
|
private $readOnly; |
|
31
|
|
|
/** |
|
32
|
|
|
* @var bool |
|
33
|
|
|
*/ |
|
34
|
|
|
private $required; |
|
35
|
|
|
/** |
|
36
|
|
|
* @var bool |
|
37
|
|
|
*/ |
|
38
|
|
|
private $searchable; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Constructor |
|
42
|
|
|
* |
|
43
|
|
|
* @param string $fieldName Field name |
|
44
|
7 |
|
* @param string $exposedName Exposed name |
|
45
|
|
|
* @param bool $readOnly Read only |
|
46
|
7 |
|
* @param bool $required Is required |
|
47
|
7 |
|
* @param bool $searchable Is searchable |
|
48
|
7 |
|
*/ |
|
49
|
7 |
|
public function __construct($fieldName, $exposedName, $readOnly, $required, $searchable) |
|
50
|
7 |
|
{ |
|
51
|
|
|
$this->fieldName = $fieldName; |
|
52
|
|
|
$this->exposedName = $exposedName; |
|
53
|
|
|
$this->readOnly = $readOnly; |
|
54
|
|
|
$this->required = $required; |
|
55
|
|
|
$this->searchable = $searchable; |
|
56
|
|
|
} |
|
57
|
5 |
|
|
|
58
|
|
|
/** |
|
59
|
5 |
|
* Get field name |
|
60
|
|
|
* |
|
61
|
|
|
* @return string |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getFieldName() |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->fieldName; |
|
66
|
|
|
} |
|
67
|
6 |
|
|
|
68
|
|
|
/** |
|
69
|
6 |
|
* Get exposed name |
|
70
|
|
|
* |
|
71
|
|
|
* @return string |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getExposedName() |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->exposedName; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Is read only |
|
80
|
|
|
* |
|
81
|
|
|
* @return bool |
|
82
|
|
|
*/ |
|
83
|
|
|
public function isReadOnly() |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->readOnly; |
|
86
|
|
|
} |
|
87
|
2 |
|
|
|
88
|
|
|
/** |
|
89
|
2 |
|
* Is required |
|
90
|
|
|
* |
|
91
|
|
|
* @return bool |
|
92
|
|
|
*/ |
|
93
|
|
|
public function isRequired() |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->required; |
|
96
|
|
|
} |
|
97
|
3 |
|
|
|
98
|
|
|
/** |
|
99
|
3 |
|
* Is searchable |
|
100
|
3 |
|
* |
|
101
|
|
|
* @return boolean |
|
102
|
|
|
*/ |
|
103
|
3 |
|
public function isSearchable() |
|
104
|
3 |
|
{ |
|
105
|
3 |
|
return $this->searchable; |
|
106
|
|
|
} |
|
107
|
3 |
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @param boolean $searchable Is searchable |
|
110
|
|
|
* |
|
111
|
|
|
* @return void |
|
112
|
|
|
*/ |
|
113
|
|
|
public function setSearchable($searchable) |
|
114
|
|
|
{ |
|
115
|
|
|
$this->searchable = $searchable; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Get form name |
|
120
|
|
|
* |
|
121
|
|
|
* @return string |
|
122
|
|
|
*/ |
|
123
|
|
|
public function getFormName() |
|
124
|
|
|
{ |
|
125
|
|
|
if (FormConfigBuilder::isValidName($this->exposedName)) { |
|
126
|
|
|
return $this->exposedName; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
$name = $this->exposedName; |
|
130
|
|
|
$name = preg_replace('/[^a-zA-Z0-9_]/', '', $name); |
|
131
|
|
|
$name = preg_replace('/[^a-zA-Z0-9_\-:]/', '', $name); |
|
132
|
|
|
|
|
133
|
|
|
return $name === '' ? $this->fieldName : $name; |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|