ResourceConfigForm: Allow to manually validate the configuration

refs #7588
This commit is contained in:
Johannes Meyer 2015-07-24 14:31:02 +02:00
parent 2c4b6eb915
commit df81fd502d
1 changed files with 83 additions and 0 deletions

View File

@ -28,6 +28,7 @@ class ResourceConfigForm extends ConfigForm
{
$this->setName('form_config_resource');
$this->setSubmitLabel($this->translate('Save Changes'));
$this->setValidatePartial(true);
}
/**
@ -279,4 +280,86 @@ class ResourceConfigForm extends ConfigForm
}
}
}
/**
* Run the configured resource's inspection checks and show the result, if necessary
*
* This will only run any validation if the user pushed the 'resource_validation' button.
*
* @param array $formData
*
* @return bool
*/
public function isValidPartial(array $formData)
{
if ($this->getElement('resource_validation')->isChecked() && parent::isValid($formData)) {
$inspection = static::inspectResource($this);
if ($inspection !== null) {
$join = function ($e) use (& $join) {
return is_string($e) ? $e : join("\n", array_map($join, $e));
};
$this->addElement(
'note',
'inspection_output',
array(
'order' => 0,
'value' => '<strong>' . $this->translate('Validation Log') . "</strong>\n\n"
. join("\n", array_map($join, $inspection->toArray())),
'decorators' => array(
'ViewHelper',
array('HtmlTag', array('tag' => 'pre', 'class' => 'log-output')),
)
)
);
if ($inspection->hasError()) {
$this->warning(sprintf(
$this->translate('Failed to successfully validate the configuration: %s'),
$inspection->getError()
));
return false;
}
}
$this->info($this->translate('The configuration has been successfully validated.'));
}
return true;
}
/**
* Add a submit button to this form and one to manually validate the configuration
*
* Calls parent::addSubmitButton() to add the submit button.
*
* @return $this
*/
public function addSubmitButton()
{
parent::addSubmitButton()
->getElement('btn_submit')
->setDecorators(array('ViewHelper'));
$this->addElement(
'submit',
'resource_validation',
array(
'ignore' => true,
'label' => $this->translate('Validate Configuration'),
'decorators' => array('ViewHelper')
)
);
$this->addDisplayGroup(
array('btn_submit', 'resource_validation'),
'submit_validation',
array(
'decorators' => array(
'FormElements',
array('HtmlTag', array('tag' => 'div', 'class' => 'control-group'))
)
)
);
return $this;
}
}