Skip to content

Commit c818ec7

Browse files
committed
Add error if decode fails
1 parent 988b334 commit c818ec7

1 file changed

Lines changed: 37 additions & 1 deletion

File tree

application/forms/ChannelForm.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66

77
use DateTime;
88
use Icinga\Exception\Http\HttpNotFoundException;
9-
use Icinga\Module\Notifications\Model\Channel;
109
use Icinga\Module\Notifications\Model\AvailableChannelType;
10+
use Icinga\Module\Notifications\Model\Channel;
1111
use Icinga\Module\Notifications\Model\Contact;
1212
use Icinga\Module\Notifications\Model\RuleEscalationRecipient;
1313
use Icinga\Web\Session;
14+
use ipl\Html\Attributes;
1415
use ipl\Html\Contract\FormSubmitElement;
1516
use ipl\Html\FormElement\BaseFormElement;
1617
use ipl\Html\FormElement\FieldsetElement;
18+
use ipl\Html\HtmlElement;
1719
use ipl\I18n\GettextTranslator;
1820
use ipl\I18n\StaticTranslator;
1921
use ipl\Sql\Connection;
@@ -267,6 +269,24 @@ protected function createConfigElements(string $type, string $config): void
267269
$elementsConfig = json_decode($config, true);
268270

269271
if (empty($elementsConfig)) {
272+
$this->prependHtml(
273+
HtmlElement::create(
274+
'ul',
275+
Attributes::create(['class' => 'errors']),
276+
HtmlElement::create(
277+
'li',
278+
null,
279+
sprintf(
280+
$this->translate(
281+
'Could not decode options for type \'%s\'.'
282+
. ' Check if your database\'s character set is correctly configured.'
283+
),
284+
$type
285+
)
286+
)
287+
)
288+
);
289+
270290
return;
271291
}
272292

@@ -449,4 +469,20 @@ private function fetchDbValues(): array
449469
'config' => json_decode($channel->config, true) ?? []
450470
];
451471
}
472+
473+
/**
474+
* Validate all elements
475+
*
476+
* @return $this
477+
*/
478+
public function validate(): self
479+
{
480+
parent::validate();
481+
482+
if (! $this->hasElement('config')) {
483+
$this->isValid = false;
484+
}
485+
486+
return $this;
487+
}
452488
}

0 commit comments

Comments
 (0)