DashletForm: Make sure that we won't try to save invalid section names

refs #3648

Signed-off-by: Eric Lippmann <eric.lippmann@icinga.com>
This commit is contained in:
Johannes Meyer 2019-02-01 10:59:31 +01:00 committed by Eric Lippmann
parent 1e0a2cdb64
commit 39dc8bcdbc
1 changed files with 15 additions and 2 deletions

View File

@ -46,6 +46,17 @@ class DashletForm extends Form
$panes = $this->dashboard->getPaneKeyTitleArray(); $panes = $this->dashboard->getPaneKeyTitleArray();
} }
$sectionNameValidator = ['Callback', true, [
'callback' => function ($value) {
if (strpos($value, '[') === false && strpos($value, ']') === false) {
return true;
}
},
'messages' => [
'callbackValue' => $this->translate('Brackets ([, ]) cannot be used here')
]
]];
$this->addElement( $this->addElement(
'hidden', 'hidden',
'org_pane', 'org_pane',
@ -80,7 +91,8 @@ class DashletForm extends Form
array( array(
'required' => true, 'required' => true,
'label' => $this->translate('Dashlet Title'), 'label' => $this->translate('Dashlet Title'),
'description' => $this->translate('Enter a title for the dashlet.') 'description' => $this->translate('Enter a title for the dashlet.'),
'validators' => [$sectionNameValidator]
) )
); );
$this->addElement( $this->addElement(
@ -109,7 +121,8 @@ class DashletForm extends Form
array( array(
'required' => true, 'required' => true,
'label' => $this->translate('New Dashboard Title'), 'label' => $this->translate('New Dashboard Title'),
'description' => $this->translate('Enter a title for the new dashboard') 'description' => $this->translate('Enter a title for the new dashboard'),
'validators' => [$sectionNameValidator]
) )
); );
} else { } else {