NavigationConfigForm: Do not show a type selection for a single choice

refs #10246
This commit is contained in:
Johannes Meyer 2015-09-29 17:07:56 +02:00
parent 6fdfef4f4a
commit 5d4f7cf2c0

View File

@ -565,6 +565,13 @@ class NavigationConfigForm extends ConfigForm
$shared = false; $shared = false;
$itemTypes = $this->getItemTypes(); $itemTypes = $this->getItemTypes();
$itemType = isset($formData['type']) ? $formData['type'] : key($itemTypes); $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); $itemForm = $this->getItemForm($itemType);
$this->addElement( $this->addElement(
@ -622,6 +629,21 @@ class NavigationConfigForm extends ConfigForm
} }
} }
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( $this->addElement(
'select', 'select',
'type', 'type',
@ -630,9 +652,10 @@ class NavigationConfigForm extends ConfigForm
'autosubmit' => true, 'autosubmit' => true,
'label' => $this->translate('Type'), 'label' => $this->translate('Type'),
'description' => $this->translate('The type of this navigation item'), 'description' => $this->translate('The type of this navigation item'),
'multiOptions' => $itemTypes 'multiOptions' => $multiOptions
) )
); );
}
if (! $shared && $itemForm->requiresParentSelection()) { if (! $shared && $itemForm->requiresParentSelection()) {
if ($this->itemToLoad && $this->hasBeenShared($this->itemToLoad)) { if ($this->itemToLoad && $this->hasBeenShared($this->itemToLoad)) {