From 5d4f7cf2c027f6836c88af773b1d4b067507b0db Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 29 Sep 2015 17:07:56 +0200 Subject: [PATCH] NavigationConfigForm: Do not show a type selection for a single choice refs #10246 --- .../forms/Navigation/NavigationConfigForm.php | 45 ++++++++++++++----- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/application/forms/Navigation/NavigationConfigForm.php b/application/forms/Navigation/NavigationConfigForm.php index cf3923d47..efbe73d60 100644 --- a/application/forms/Navigation/NavigationConfigForm.php +++ b/application/forms/Navigation/NavigationConfigForm.php @@ -565,6 +565,13 @@ class NavigationConfigForm extends ConfigForm $shared = false; $itemTypes = $this->getItemTypes(); $itemType = isset($formData['type']) ? $formData['type'] : key($itemTypes); + if ($itemType === null) { + throw new ProgrammingError( + 'This should actually not happen. Create a bug report at dev.icinga.org' + . ' or remove this assertion if you know what you\'re doing' + ); + } + $itemForm = $this->getItemForm($itemType); $this->addElement( @@ -622,17 +629,33 @@ class NavigationConfigForm extends ConfigForm } } - $this->addElement( - 'select', - 'type', - array( - 'required' => true, - 'autosubmit' => true, - 'label' => $this->translate('Type'), - 'description' => $this->translate('The type of this navigation item'), - 'multiOptions' => $itemTypes - ) - ); + if (empty($itemTypes) || count($itemTypes) === 1) { + $this->addElement( + 'hidden', + 'type', + array( + 'disabled' => true, + 'value' => $itemType + ) + ); + } else { + $multiOptions = array(); + foreach ($itemTypes as $type => $options) { + $multiOptions[$type] = isset($options['label']) ? $options['label'] : $type; + } + + $this->addElement( + 'select', + 'type', + array( + 'required' => true, + 'autosubmit' => true, + 'label' => $this->translate('Type'), + 'description' => $this->translate('The type of this navigation item'), + 'multiOptions' => $multiOptions + ) + ); + } if (! $shared && $itemForm->requiresParentSelection()) { if ($this->itemToLoad && $this->hasBeenShared($this->itemToLoad)) {