DataTypeSqlQuery: do not break form on errors
This commit is contained in:
parent
43fc6fc42b
commit
24f7e36e92
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Icinga\Module\Director\DataType;
|
namespace Icinga\Module\Director\DataType;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use Icinga\Data\Db\DbConnection;
|
use Icinga\Data\Db\DbConnection;
|
||||||
use Icinga\Module\Director\Web\Form\QuickForm;
|
use Icinga\Module\Director\Web\Form\QuickForm;
|
||||||
use Icinga\Module\Director\Web\Hook\DataTypeHook;
|
use Icinga\Module\Director\Web\Hook\DataTypeHook;
|
||||||
|
@ -17,11 +18,22 @@ class DataTypeSqlQuery extends DataTypeHook
|
||||||
|
|
||||||
public function getFormElement($name, QuickForm $form)
|
public function getFormElement($name, QuickForm $form)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
|
$data = $this->fetchData();
|
||||||
|
$error = false;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$data = array();
|
||||||
|
$error = sprintf($form->translate('Unable to fetch data: %s'), $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
$element = $form->createElement('select', $name, array(
|
$element = $form->createElement('select', $name, array(
|
||||||
'multiOptions' => array(null => '- please choose -') +
|
'multiOptions' => $form->optionalEnum($data),
|
||||||
$this->fetchData(),
|
|
||||||
));
|
));
|
||||||
|
|
||||||
|
if ($error) {
|
||||||
|
$element->addError($error);
|
||||||
|
}
|
||||||
|
|
||||||
return $element;
|
return $element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue