DataTypeSqlQuery: do not break form on errors

This commit is contained in:
Thomas Gelf 2015-07-31 14:47:03 +02:00
parent 43fc6fc42b
commit 24f7e36e92
1 changed files with 14 additions and 2 deletions

View File

@ -2,6 +2,7 @@
namespace Icinga\Module\Director\DataType;
use Exception;
use Icinga\Data\Db\DbConnection;
use Icinga\Module\Director\Web\Form\QuickForm;
use Icinga\Module\Director\Web\Hook\DataTypeHook;
@ -17,11 +18,22 @@ class DataTypeSqlQuery extends DataTypeHook
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(
'multiOptions' => array(null => '- please choose -') +
$this->fetchData(),
'multiOptions' => $form->optionalEnum($data),
));
if ($error) {
$element->addError($error);
}
return $element;
}