IcingaHostForm: no groups element with no groups

This commit is contained in:
Thomas Gelf 2016-03-07 18:38:07 +01:00
parent 7ef09b99dc
commit c8a95f1de6
1 changed files with 24 additions and 13 deletions

View File

@ -25,19 +25,7 @@ class IcingaHostForm extends DirectorObjectForm
) )
)); ));
$this->addElement('extensibleSet', 'groups', array( $this->addGroupsElement();
'label' => $this->translate('Groups'),
'multiOptions' => $this->optionallyAddFromEnum($this->enumHostgroups()),
'positional' => false,
'description' => $this->translate(
'Hostgroups that should be directly assigned to this node. Hostgroups can be useful'
. ' for various reasons. You might assign service checks based on assigned hostgroup.'
. ' They are also often used as an instrument to enforce restricted views in Icinga Web 2.'
. ' Hostgroups can be directly assigned to single hosts or to host templates. You might'
. ' also want to consider assigning hostgroups using apply rules'
)
));
$this->addImportsElement(); $this->addImportsElement();
$this->addElement('text', 'display_name', array( $this->addElement('text', 'display_name', array(
@ -134,6 +122,29 @@ class IcingaHostForm extends DirectorObjectForm
$this->setButtons(); $this->setButtons();
} }
protected function addGroupsElement()
{
$groups = $this->enumHostgroups();
if (empty($groups)) {
return $this;
}
$this->addElement('extensibleSet', 'groups', array(
'label' => $this->translate('Groups'),
'multiOptions' => $this->optionallyAddFromEnum($groups),
'positional' => false,
'description' => $this->translate(
'Hostgroups that should be directly assigned to this node. Hostgroups can be useful'
. ' for various reasons. You might assign service checks based on assigned hostgroup.'
. ' They are also often used as an instrument to enforce restricted views in Icinga Web 2.'
. ' Hostgroups can be directly assigned to single hosts or to host templates. You might'
. ' also want to consider assigning hostgroups using apply rules'
)
));
return $this;
}
protected function enumHostgroups() protected function enumHostgroups()
{ {
$db = $this->db->getDbAdapter(); $db = $this->db->getDbAdapter();