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
|
|
|
* @param string $exposedName Exposed name |
45
|
|
|
* @param bool $readOnly Read only |
46
|
|
|
* @param bool $required Is required |
47
|
|
|
*/ |
48
|
|
|
public function __construct($fieldName, $exposedName, $readOnly, $required) |
49
|
|
|
{ |
50
|
|
|
$this->fieldName = $fieldName; |
51
|
|
|
$this->exposedName = $exposedName; |
52
|
|
|
$this->readOnly = $readOnly; |
53
|
|
|
$this->required = $required; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get field name |
58
|
|
|
* |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
|
|
public function getFieldName() |
62
|
|
|
{ |
63
|
|
|
return $this->fieldName; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Get exposed name |
68
|
|
|
* |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
public function getExposedName() |
72
|
|
|
{ |
73
|
|
|
return $this->exposedName; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Is read only |
78
|
|
|
* |
79
|
|
|
* @return bool |
80
|
|
|
*/ |
81
|
|
|
public function isReadOnly() |
82
|
|
|
{ |
83
|
|
|
return $this->readOnly; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Is required |
88
|
|
|
* |
89
|
|
|
* @return bool |
90
|
|
|
*/ |
91
|
|
|
public function isRequired() |
92
|
|
|
{ |
93
|
|
|
return $this->required; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Is searchable |
98
|
|
|
* |
99
|
|
|
* @return bool |
100
|
|
|
*/ |
101
|
|
|
public function isSearchable() |
102
|
|
|
{ |
103
|
|
|
return $this->searchable; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Get form name |
108
|
|
|
* |
109
|
|
|
* @return string |
110
|
|
|
*/ |
111
|
|
|
public function getFormName() |
112
|
|
|
{ |
113
|
|
|
if (FormConfigBuilder::isValidName($this->exposedName)) { |
114
|
|
|
return $this->exposedName; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
$name = $this->exposedName; |
118
|
|
|
$name = preg_replace('/[^a-zA-Z0-9_]/', '', $name); |
119
|
|
|
$name = preg_replace('/[^a-zA-Z0-9_\-:]/', '', $name); |
120
|
|
|
|
121
|
|
|
return $name === '' ? $this->fieldName : $name; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|