From c8a95f1de6f0aa2dc8b4317725b0cc423cf5b0f6 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 7 Mar 2016 18:38:07 +0100 Subject: [PATCH] IcingaHostForm: no groups element with no groups --- application/forms/IcingaHostForm.php | 37 ++++++++++++++++++---------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/application/forms/IcingaHostForm.php b/application/forms/IcingaHostForm.php index 2105c251..d120f523 100644 --- a/application/forms/IcingaHostForm.php +++ b/application/forms/IcingaHostForm.php @@ -25,19 +25,7 @@ class IcingaHostForm extends DirectorObjectForm ) )); - $this->addElement('extensibleSet', 'groups', array( - '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->addGroupsElement(); $this->addImportsElement(); $this->addElement('text', 'display_name', array( @@ -134,6 +122,29 @@ class IcingaHostForm extends DirectorObjectForm $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() { $db = $this->db->getDbAdapter();