Make isValid more compact and fix coding style

refs #5525
This commit is contained in:
Johannes Meyer 2014-07-24 09:05:10 +02:00
parent edf49d091e
commit 9c434fe8bf

View File

@ -28,35 +28,36 @@ abstract class BaseBackendForm extends Form
} }
/** /**
* Validate this form with the Zend validation mechanism and perform a logic validation of the connection. * Return whether the given values are complete/valid and check whether it is possible to connect to the backend
* *
* If logic validation fails, the 'backend_force_creation' checkbox is prepended to the form to allow users to * If connection validation fails, a checkbox is prepended to the form to allow users to skip it.
* skip the logic connection validation.
* *
* @param array $data The form input to validate * @param array $data The data to validate
* *
* @return bool Whether validation succeeded or not * @return bool Whether the validation succeeded or not
*/ */
public function isValid($data) public function isValid($data)
{ {
if (!parent::isValid($data)) { if (false === parent::isValid($data)) {
return false; return false;
} }
if (isset($data['backend_force_creation']) && $data['backend_force_creation']) {
return true; if (
} (false === isset($data['force_creation']) || false === $data['force_creation'])
if (!$this->isValidAuthenticationBackend()) { && false === $this->isValidAuthenticationBackend()
) {
$this->addForceCreationCheckbox(); $this->addForceCreationCheckbox();
return false; return false;
} }
return true; return true;
} }
/** /**
* Validate the configuration state of this backend with the concrete authentication backend. * Validate the configuration state of this backend with the concrete authentication backend.
* *
* An implementation should not throw any exception, but use the add/setErrorMessages method of * An implementation should not throw any exception, but use the add/setErrorMessages method
* Zend_Form. If the 'backend_force_creation' checkbox is set, this method won't be called. * of Zend_Form. If the 'force_creation' checkbox is set, this method won't be called.
* *
* @return bool Whether validation succeeded or not * @return bool Whether validation succeeded or not
*/ */