-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventRuleForm.php
More file actions
84 lines (70 loc) · 2.12 KB
/
Copy pathEventRuleForm.php
File metadata and controls
84 lines (70 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
// SPDX-FileCopyrightText: 2023 Icinga GmbH <https://icinga.com>
// SPDX-License-Identifier: GPL-3.0-or-later
namespace Icinga\Module\Notifications\Forms;
use ipl\Html\FormDecoration\DescriptionDecorator;
use ipl\I18n\Translation;
use ipl\Web\Common\CsrfCounterMeasure;
use ipl\Web\Compat\CompatForm;
class EventRuleForm extends CompatForm
{
use CsrfCounterMeasure;
use Translation;
/** @var array<int, string> */
protected array $sources = [];
/** @var bool Whether this form is for a new rule */
protected bool $isNew = false;
/**
* Set the sources to choose from
*
* @param array<int, string> $sources
*
* @return $this
*/
public function setAvailableSources(array $sources): self
{
$this->sources = $sources;
return $this;
}
/**
* Set whether this form is for a new rule
*
* @return $this
*/
public function setIsNew(): static
{
$this->isNew = true;
return $this;
}
protected function assemble(): void
{
$this->applyDefaultElementDecorators();
$this->addCsrfCounterMeasure();
$this->addElement(
'text',
'name',
[
'label' => $this->translate('Title'),
'required' => true
]
);
$this->addElement('select', 'source', [
'label' => $this->translate('Source'),
'required' => true,
'options' => ['' => ' - ' . $this->translate('Please choose') . ' - '] + $this->sources,
'disabledOptions' => [''],
'value' => ''
]);
if (! $this->isNew) {
$this->getElement('source')
->setDescription($this->translate(
'Choosing a different source will reset all filters of the rule'
))
->getDecorators()
->replaceDecorator('Description', DescriptionDecorator::class, ['class' => 'description']);
}
$this->addElement('submit', 'btn_submit', [
'label' => $this->translate('Save')
]);
}
}