|
6 | 6 |
|
7 | 7 | use DateTime; |
8 | 8 | use Icinga\Exception\Http\HttpNotFoundException; |
9 | | -use Icinga\Module\Notifications\Model\Channel; |
10 | 9 | use Icinga\Module\Notifications\Model\AvailableChannelType; |
| 10 | +use Icinga\Module\Notifications\Model\Channel; |
11 | 11 | use Icinga\Module\Notifications\Model\Contact; |
12 | 12 | use Icinga\Module\Notifications\Model\RuleEscalationRecipient; |
13 | 13 | use Icinga\Web\Session; |
| 14 | +use ipl\Html\Attributes; |
14 | 15 | use ipl\Html\Contract\FormSubmitElement; |
15 | 16 | use ipl\Html\FormElement\BaseFormElement; |
16 | 17 | use ipl\Html\FormElement\FieldsetElement; |
| 18 | +use ipl\Html\HtmlElement; |
17 | 19 | use ipl\I18n\GettextTranslator; |
18 | 20 | use ipl\I18n\StaticTranslator; |
19 | 21 | use ipl\Sql\Connection; |
@@ -267,6 +269,24 @@ protected function createConfigElements(string $type, string $config): void |
267 | 269 | $elementsConfig = json_decode($config, true); |
268 | 270 |
|
269 | 271 | 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 | + |
270 | 290 | return; |
271 | 291 | } |
272 | 292 |
|
@@ -449,4 +469,20 @@ private function fetchDbValues(): array |
449 | 469 | 'config' => json_decode($channel->config, true) ?? [] |
450 | 470 | ]; |
451 | 471 | } |
| 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 | + } |
452 | 488 | } |
0 commit comments