-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathPerfdataConsumerForm.php
More file actions
98 lines (84 loc) · 3.04 KB
/
Copy pathPerfdataConsumerForm.php
File metadata and controls
98 lines (84 loc) · 3.04 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
namespace Icinga\Module\Vspheredb\Web\Form;
use ipl\I18n\Translation;
use gipfl\Web\Form\Decorator\DdDtDecorator;
use gipfl\ZfDbStore\Store;
use Icinga\Module\Vspheredb\Daemon\RemoteClient;
use Icinga\Module\Vspheredb\Hook\PerfDataConsumerHook;
use Icinga\Module\Vspheredb\Storable\PerfdataConsumer;
use ipl\Html\FormElement\SubmitElement;
use React\EventLoop\LoopInterface;
class PerfdataConsumerForm extends ObjectForm
{
use FormElementStealer;
use Translation;
public const ON_DELETE = 'delete';
protected $class = PerfdataConsumer::class;
/** @var RemoteClient */
protected $client;
/** @var LoopInterface */
protected $loop;
public function __construct(LoopInterface $loop, RemoteClient $client, Store $store)
{
$this->loop = $loop;
$this->client = $client;
parent::__construct($store);
}
public function assemble()
{
$this->addElement('text', 'name', [
'label' => $this->translate('Name'),
'required' => true,
'description' => $this->translate('Arbitrary unique name for this Performance Data Consumer'),
]);
$this->addElement('boolean', 'enabled', [
'label' => $this->translate('Enabled'),
'value' => 'y',
'required' => true,
]);
if ($this->object instanceof PerfdataConsumer && !$this->hasBeenSent()) {
$this->populate((array) $this->object->settings());
}
if ($implementation = $this->selectImplementation()) {
$this->addImplementation($implementation);
}
// TODO: web 2.9 broke Multiselect for nested options
// $this->addPerformanceSets();
$this->addButtons(isset($implementation), 'implementation');
}
public function isValidEvent($event): bool
{
if ($event === self::ON_DELETE) {
return true;
}
return parent::isValidEvent($event);
}
protected function selectImplementation()
{
if (! $this->isNew()) {
return $this->object->get('implementation');
}
$this->addElement('select', 'implementation', [
'label' => $this->translate('Implementation'),
'options' => ['' => $this->translate('- please choose -')] + PerfDataConsumerHook::enum(),
'required' => true,
'class' => 'autosubmit',
]);
return $this->getValue('implementation');
}
protected function addImplementation($implementation)
{
/** @var PerfDataConsumerHook $instance */
$class = PerfDataConsumerHook::getClass($implementation);
if (! $class || ! class_exists($class)) {
$this->triggerElementError('implementation', sprintf(
$this->translate('There is no such PerfdataConsumer: %s'),
$implementation
));
return;
}
$instance = new $class();
$instance->setLoop($this->loop);
$this->addFormElementsFrom($instance->getConfigurationForm($this->client));
}
}