-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathPatternDefinitionField.php
189 lines (170 loc) · 3.32 KB
/
PatternDefinitionField.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php
namespace Drupal\ui_patterns\Definition;
/**
* Class PatternDefinitionField.
*
* @package Drupal\ui_patterns\Definition
*/
class PatternDefinitionField implements \ArrayAccess {
use ArrayAccessDefinitionTrait;
/**
* Default field values.
*
* @var array
*/
protected $definition = [
'name' => NULL,
'label' => NULL,
'description' => NULL,
'type' => NULL,
'preview' => NULL,
'escape' => TRUE,
'additional' => [],
];
/**
* PatternDefinitionField constructor.
*/
public function __construct($name, $value) {
if (is_scalar($value)) {
$this->definition['name'] = is_numeric($name) ? $value : $name;
$this->definition['label'] = $value;
}
else {
$this->definition['name'] = !isset($value['name']) ? $name : $value['name'];
$this->definition['label'] = $value['label'];
$this->definition = $value + $this->definition;
}
}
/**
* Return array definition.
*
* @return array
* Array definition.
*/
public function toArray() {
return $this->definition;
}
/**
* Get Name property.
*
* @return mixed
* Property value.
*/
public function getName() {
return $this->definition['name'];
}
/**
* Get Label property.
*
* @return mixed
* Property value.
*/
public function getLabel() {
return $this->definition['label'];
}
/**
* Get Description property.
*
* @return string
* Property value.
*/
public function getDescription() {
return $this->definition['description'];
}
/**
* Set Description property.
*
* @param string $description
* Property value.
*
* @return $this
*/
public function setDescription($description) {
$this->definition['description'] = $description;
return $this;
}
/**
* Get Type property.
*
* @return string
* Property value.
*/
public function getType() {
return $this->definition['type'];
}
/**
* Set Type property.
*
* @param string $type
* Property value.
*
* @return $this
*/
public function setType($type) {
$this->definition['type'] = $type;
return $this;
}
/**
* Get Preview property.
*
* @return mixed
* Property value.
*/
public function getPreview() {
return $this->definition['preview'];
}
/**
* Set Preview property.
*
* @param mixed $preview
* Property value.
*
* @return $this
*/
public function setPreview($preview) {
$this->definition['preview'] = $preview;
return $this;
}
/**
* Get Escape property.
*
* @return bool
* Property value.
*/
public function getEscape() {
return $this->definition['escape'];
}
/**
* Set Escape property.
*
* @param bool $escape
* Property value.
*
* @return $this
*/
public function setEscape($escape) {
$this->definition['escape'] = $escape;
return $this;
}
/**
* Get Additional property.
*
* @return array
* Property value.
*/
public function getAdditional() {
return $this->definition['additional'];
}
/**
* Set Additional property.
*
* @param array $additional
* Property value.
*
* @return $this
*/
public function setAdditional(array $additional) {
$this->definition['additional'] = $additional;
return $this;
}
}