IcingaCommandArgumentForm: detect custom variables
This commit is contained in:
parent
88d87b1e5c
commit
ad27ab206d
|
@ -27,6 +27,19 @@ class IcingaCommandArgumentForm extends DirectorObjectForm
|
|||
|
||||
$this->addHidden('value_format', 'string'); // expression, json?
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function beforeValidation($data = array())
|
||||
{
|
||||
if (isset($data['argument_value']) && $value = $data['argument_value']) {
|
||||
if (preg_match_all('/\$([a-z0-9_]+)\$/', $value, $m, PREG_PATTERN_ORDER)) {
|
||||
foreach ($m[1] as $var) {
|
||||
$this->addCustomVariable($var);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
$this->optionalBoolean(
|
||||
'required',
|
||||
|
@ -36,4 +49,22 @@ class IcingaCommandArgumentForm extends DirectorObjectForm
|
|||
*/
|
||||
$this->addElement('submit', $this->translate('Store'));
|
||||
}
|
||||
|
||||
protected function addCustomVariable($varname)
|
||||
{
|
||||
$a = new \Zend_Form_SubForm();
|
||||
$a->addElement('note', 'title', array(
|
||||
'label' => sprintf($this->translate('Custom Variable "%s"'), $varname),
|
||||
));
|
||||
|
||||
$a->addElement('text', 'description', array(
|
||||
'label' => $this->translate('Description'),
|
||||
'required' => true,
|
||||
));
|
||||
|
||||
$a->addElement('text', 'default_value', array(
|
||||
'label' => $this->translate('Default value'),
|
||||
));
|
||||
$this->addSubForm($a, 'cv_' . $varname);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue