From ceb32679d8247a4eec3afaf2240023da529907d3 Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Mon, 3 Aug 2015 16:52:50 +0200 Subject: [PATCH] RemoteInstanceForm: Fix the unhandled exception if no ... ..resources are available * Now we only can use the ssh identity, if there is at least one ssh identity resource exists fixes #9517 --- .../Config/Instance/RemoteInstanceForm.php | 44 ++++++++++++++----- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/modules/monitoring/application/forms/Config/Instance/RemoteInstanceForm.php b/modules/monitoring/application/forms/Config/Instance/RemoteInstanceForm.php index 244bf66d1..e290866cc 100644 --- a/modules/monitoring/application/forms/Config/Instance/RemoteInstanceForm.php +++ b/modules/monitoring/application/forms/Config/Instance/RemoteInstanceForm.php @@ -52,24 +52,46 @@ class RemoteInstanceForm extends Form return $this; } + /** + * Check whether ssh identity resources exists or not + * + * @return boolean + */ + public function hasResources() + { + $resourceConfig = ResourceFactory::getResourceConfigs(); + + foreach ($resourceConfig as $name => $resource) { + if ($resource->type === 'ssh') { + return true; + } + } + return false; + } + /** * (non-PHPDoc) * @see Form::createElements() For the method documentation. */ public function createElements(array $formData = array()) { - $useResource = isset($formData['use_resource']) ? $formData['use_resource'] : $this->getValue('use_resource'); + $useResource = false; - $this->addElement( - 'checkbox', - 'use_resource', - array( - 'label' => $this->translate('Use SSH Identity'), - 'description' => $this->translate('Make use of the ssh identity resource'), - 'autosubmit' => true, - 'ignore' => true - ) - ); + if ($this->hasResources()) { + $useResource = isset($formData['use_resource']) + ? $formData['use_resource'] : $this->getValue('use_resource'); + + $this->addElement( + 'checkbox', + 'use_resource', + array( + 'label' => $this->translate('Use SSH Identity'), + 'description' => $this->translate('Make use of the ssh identity resource'), + 'autosubmit' => true, + 'ignore' => true + ) + ); + } if ($useResource) {