UserBackendConfigForm: Allow to manually validate the configuration
refs #7588
This commit is contained in:
parent
b3e6b2755c
commit
ccc809853a
|
@ -44,6 +44,7 @@ class UserBackendConfigForm extends ConfigForm
|
|||
{
|
||||
$this->setName('form_config_authbackend');
|
||||
$this->setSubmitLabel($this->translate('Save Changes'));
|
||||
$this->setValidatePartial(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -399,4 +400,86 @@ class UserBackendConfigForm extends ConfigForm
|
|||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the configured backend's inspection checks and show the result, if necessary
|
||||
*
|
||||
* This will only run any validation if the user pushed the 'backend_validation' button.
|
||||
*
|
||||
* @param array $formData
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isValidPartial(array $formData)
|
||||
{
|
||||
if ($this->getElement('backend_validation')->isChecked() && parent::isValid($formData)) {
|
||||
$inspection = static::inspectUserBackend($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',
|
||||
'backend_validation',
|
||||
array(
|
||||
'ignore' => true,
|
||||
'label' => $this->translate('Validate Configuration'),
|
||||
'decorators' => array('ViewHelper')
|
||||
)
|
||||
);
|
||||
$this->addDisplayGroup(
|
||||
array('btn_submit', 'backend_validation'),
|
||||
'submit_validation',
|
||||
array(
|
||||
'decorators' => array(
|
||||
'FormElements',
|
||||
array('HtmlTag', array('tag' => 'div', 'class' => 'control-group'))
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,15 @@ p code {
|
|||
padding: 0.3em;
|
||||
}
|
||||
|
||||
pre.log-output {
|
||||
padding: 0.5em;
|
||||
margin-top: 0;
|
||||
margin-bottom: 2em;
|
||||
max-height: 12em;
|
||||
overflow: auto;
|
||||
border: 1px solid #ddd;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #39a;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue