Skip to content

Commit 0d13629

Browse files
committed
IcingaMultiEditForm: Fix editing custom vars with space in their name
1 parent 428a49f commit 0d13629

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

application/forms/IcingaMultiEditForm.php

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class IcingaMultiEditForm extends DirectorObjectForm
2121

2222
private $propertiesToPick;
2323

24+
/** @var array Custom variable name map to its element's name in the form */
25+
private $varNameMap = [];
26+
2427
public function setObjects($objects)
2528
{
2629
$this->objects = $objects;
@@ -68,8 +71,7 @@ public function setup()
6871

6972
/** @var \Zend_Form_Element $el */
7073
foreach ($this->getElements() as $el) {
71-
$name = $el->getName();
72-
if (substr($name, 0, 4) === 'var_') {
74+
if ($this->isCustomVar($el->getName())) {
7375
$this->makeVariants($el);
7476
}
7577
}
@@ -137,8 +139,8 @@ protected function setSubmittedMultiValue($key, $value)
137139
continue;
138140
}
139141

140-
if (substr($property, 0, 4) === 'var_') {
141-
$property = 'vars.' . substr($property, 4);
142+
if ($this->isCustomVar($property)) {
143+
$property = 'vars.' . $this->varNameMap[$property];
142144
}
143145

144146
foreach ($this->getObjects($objects) as $object) {
@@ -147,6 +149,18 @@ protected function setSubmittedMultiValue($key, $value)
147149
}
148150
}
149151

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+
150164
protected function storeModifiedObjects()
151165
{
152166
$modified = 0;
@@ -222,6 +236,11 @@ protected function makeVariants(ZfElement $element)
222236
$key = $element->getName();
223237
$this->removeElement($key);
224238
$label = $element->getLabel();
239+
240+
if ($this->isCustomVar($key)) {
241+
$this->varNameMap[$key] = $label;
242+
}
243+
225244
$group = $this->getDisplayGroupForElement($element);
226245
$description = $element->getDescription();
227246

@@ -241,11 +260,13 @@ protected function makeVariants(ZfElement $element)
241260
}
242261
}
243262

263+
264+
244265
protected function getVariants($key)
245266
{
246267
$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];
249270
}
250271

251272
foreach ($this->objects as $name => $object) {

0 commit comments

Comments
 (0)