IcingaServiceForm: combine duplicate code

This commit is contained in:
Thomas Gelf 2022-02-06 12:31:59 +01:00
parent c296b716de
commit 21a67e355f

View File

@ -497,13 +497,7 @@ class IcingaServiceForm extends DirectorObjectForm
->addExtraInfoElements() ->addExtraInfoElements()
->setButtons(); ->setButtons();
if ($this->hasBeenSent()) { $this->setDefaultNameFromTemplate($imports);
$name = $this->getSentOrObjectValue('object_name');
if (!strlen($name)) {
$this->setElementValue('object_name', end($imports));
$this->object->object_name = end($imports);
}
}
} }
/** /**
@ -547,13 +541,7 @@ class IcingaServiceForm extends DirectorObjectForm
->addExtraInfoElements(); ->addExtraInfoElements();
} }
if ($this->hasBeenSent()) { $this->setDefaultNameFromTemplate($imports);
$name = $this->getSentOrObjectValue('object_name');
if (!strlen($name)) {
$this->setElementValue('object_name', end($imports));
$this->object->object_name = end($imports);
}
}
} }
public function setServiceSet(IcingaServiceSet $set) public function setServiceSet(IcingaServiceSet $set)
@ -759,4 +747,18 @@ class IcingaServiceForm extends DirectorObjectForm
return parent::onSuccess(); return parent::onSuccess();
} }
/**
* @param array $imports
*/
protected function setDefaultNameFromTemplate($imports)
{
if ($this->hasBeenSent()) {
$name = $this->getSentOrObjectValue('object_name');
if (!strlen($name)) {
$this->setElementValue('object_name', end($imports));
$this->object->set('object_name', end($imports));
}
}
}
} }