@@ -21,6 +21,9 @@ class IcingaMultiEditForm extends DirectorObjectForm
21
21
22
22
private $ propertiesToPick ;
23
23
24
+ /** @var array Custom variable name map to its element's name in the form */
25
+ private $ varNameMap = [];
26
+
24
27
public function setObjects ($ objects )
25
28
{
26
29
$ this ->objects = $ objects ;
@@ -68,8 +71,7 @@ public function setup()
68
71
69
72
/** @var \Zend_Form_Element $el */
70
73
foreach ($ this ->getElements () as $ el ) {
71
- $ name = $ el ->getName ();
72
- if (substr ($ name , 0 , 4 ) === 'var_ ' ) {
74
+ if ($ this ->isCustomVar ($ el ->getName ())) {
73
75
$ this ->makeVariants ($ el );
74
76
}
75
77
}
@@ -137,8 +139,8 @@ protected function setSubmittedMultiValue($key, $value)
137
139
continue ;
138
140
}
139
141
140
- if (substr ($ property, 0 , 4 ) === ' var_ ' ) {
141
- $ property = 'vars. ' . substr ( $ property, 4 ) ;
142
+ if ($ this -> isCustomVar ($ property) ) {
143
+ $ property = 'vars. ' . $ this -> varNameMap [ $ property] ;
142
144
}
143
145
144
146
foreach ($ this ->getObjects ($ objects ) as $ object ) {
@@ -147,6 +149,18 @@ protected function setSubmittedMultiValue($key, $value)
147
149
}
148
150
}
149
151
152
+ /**
153
+ * Check if the given property is a custom var
154
+ *
155
+ * @param string $property
156
+ *
157
+ * @return bool
158
+ */
159
+ protected function isCustomVar (string $ property ): bool
160
+ {
161
+ return substr ($ property , 0 , 4 ) === 'var_ ' ;
162
+ }
163
+
150
164
protected function storeModifiedObjects ()
151
165
{
152
166
$ modified = 0 ;
@@ -222,6 +236,11 @@ protected function makeVariants(ZfElement $element)
222
236
$ key = $ element ->getName ();
223
237
$ this ->removeElement ($ key );
224
238
$ label = $ element ->getLabel ();
239
+
240
+ if ($ this ->isCustomVar ($ key )) {
241
+ $ this ->varNameMap [$ key ] = $ label ;
242
+ }
243
+
225
244
$ group = $ this ->getDisplayGroupForElement ($ element );
226
245
$ description = $ element ->getDescription ();
227
246
@@ -241,11 +260,13 @@ protected function makeVariants(ZfElement $element)
241
260
}
242
261
}
243
262
263
+
264
+
244
265
protected function getVariants ($ key )
245
266
{
246
267
$ variants = array ();
247
- if (substr ($ key, 0 , 4 ) === ' var_ ' ) {
248
- $ key = 'vars. ' . substr ( $ key, 4 ) ;
268
+ if ($ this -> isCustomVar ($ key) ) {
269
+ $ key = 'vars. ' . $ this -> varNameMap [ $ key] ;
249
270
}
250
271
251
272
foreach ($ this ->objects as $ name => $ object ) {
0 commit comments