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
This commit is contained in:
Alexander Fuhr 2015-08-03 16:52:50 +02:00
parent 66edf55ca6
commit ceb32679d8

View File

@ -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) {