From: Alexander Ebert Date: Wed, 22 Feb 2012 22:05:55 +0000 (+0100) Subject: Implemented error handling within FormDocument X-Git-Tag: 2.0.0_Beta_1~1317 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=9b6239138cbc9b4728f8b734f9b7a33b84105fd3;p=GitHub%2FWoltLab%2FWCF.git Implemented error handling within FormDocument Fixes #436 --- diff --git a/wcfsetup/install/files/lib/system/form/FormDocument.class.php b/wcfsetup/install/files/lib/system/form/FormDocument.class.php index 160365941e..7976f3d2f1 100644 --- a/wcfsetup/install/files/lib/system/form/FormDocument.class.php +++ b/wcfsetup/install/files/lib/system/form/FormDocument.class.php @@ -121,4 +121,17 @@ class FormDocument { } } } + + /** + * Sets localized error message for given element. + * + * @param string $name + * @param string $error + * @param unknown_type $error + */ + public function setError($name, $error) { + foreach ($this->container as $container) { + $this->containers->setError($name, $error); + } + } } diff --git a/wcfsetup/install/files/lib/system/form/IFormElement.class.php b/wcfsetup/install/files/lib/system/form/IFormElement.class.php index 3f824892bc..295abcc61c 100644 --- a/wcfsetup/install/files/lib/system/form/IFormElement.class.php +++ b/wcfsetup/install/files/lib/system/form/IFormElement.class.php @@ -61,4 +61,18 @@ interface IFormElement { * @return string */ public function getHTML($formName); + + /** + * Sets localized error message. + * + * @param string $error + */ + public function setError($error); + + /** + * Returns localized error message, empty if no error occured. + * + * @return string + */ + public function getError(); } diff --git a/wcfsetup/install/files/lib/system/form/IFormElementContainer.class.php b/wcfsetup/install/files/lib/system/form/IFormElementContainer.class.php index e52a1bce00..9c4dfe414e 100644 --- a/wcfsetup/install/files/lib/system/form/IFormElementContainer.class.php +++ b/wcfsetup/install/files/lib/system/form/IFormElementContainer.class.php @@ -83,4 +83,12 @@ interface IFormElementContainer { * @return string */ public function getHTML($formName); + + /** + * Sets localized error message for named element. + * + * @param string $name + * @param string $error + */ + public function setError($name, $error); } diff --git a/wcfsetup/install/files/lib/system/form/container/AbstractFormElementContainer.class.php b/wcfsetup/install/files/lib/system/form/container/AbstractFormElementContainer.class.php index afaf92a45e..a8115d71d6 100644 --- a/wcfsetup/install/files/lib/system/form/container/AbstractFormElementContainer.class.php +++ b/wcfsetup/install/files/lib/system/form/container/AbstractFormElementContainer.class.php @@ -104,7 +104,7 @@ abstract class AbstractFormElementContainer implements IFormElementContainer { public function handleRequest(array $variables) { foreach ($this->children as $element) { if (!($element instanceof AbstractNamedFormElement)) { - return; + continue; } if (isset($variables[$element->getName()])) { @@ -112,4 +112,19 @@ abstract class AbstractFormElementContainer implements IFormElementContainer { } } } + + /** + * @see wcf\system\form\IFormElementContainer::setError() + */ + public function setError($name, $error) { + foreach ($this->children as $element) { + if (!($element instanceof AbstractNamedFormElement)) { + continue; + } + + if ($element->getName() == $name) { + $element->setError($error); + } + } + } } diff --git a/wcfsetup/install/files/lib/system/form/element/AbstractFormElement.class.php b/wcfsetup/install/files/lib/system/form/element/AbstractFormElement.class.php index 7aa0066147..766dfd6dff 100644 --- a/wcfsetup/install/files/lib/system/form/element/AbstractFormElement.class.php +++ b/wcfsetup/install/files/lib/system/form/element/AbstractFormElement.class.php @@ -21,6 +21,12 @@ abstract class AbstractFormElement implements IFormElement { */ protected $description = ''; + /** + * localized error string + * @var string + */ + protected $error = ''; + /** * element label * @var string @@ -74,4 +80,36 @@ abstract class AbstractFormElement implements IFormElement { public function getParent() { return $this->parent; } + + /** + * @see wcf\system\form\IFormElement::setError() + */ + public function setError($error) { + $this->error = $error; + } + + /** + * @see wcf\system\form\IFormElement::getError() + */ + public function getError() { + return $this->error; + } + + /** + * Returns class attribute if an error occured. + * + * @return string + */ + protected function getErrorClass() { + return ($this->getError()) ? ' class="wcf-formError"' : ''; + } + + /** + * Returns an error message if occured. + * + * @return string + */ + protected function getErrorField() { + return ($this->getError()) ? ''.$this->getError().'' : ''; + } } diff --git a/wcfsetup/install/files/lib/system/form/element/LabelFormElement.class.php b/wcfsetup/install/files/lib/system/form/element/LabelFormElement.class.php index 00f86bcd70..2e8046c559 100644 --- a/wcfsetup/install/files/lib/system/form/element/LabelFormElement.class.php +++ b/wcfsetup/install/files/lib/system/form/element/LabelFormElement.class.php @@ -42,11 +42,12 @@ class LabelFormElement extends AbstractFormElement { */ public function getHTML($formName) { return << +getErrorClass()}>
{$this->getText()} {$this->getDescription()} + {$this->getErrorField()}
HTML; diff --git a/wcfsetup/install/files/lib/system/form/element/PasswordInputFormElement.class.php b/wcfsetup/install/files/lib/system/form/element/PasswordInputFormElement.class.php index 4c6ba3e339..8ffaa8d388 100644 --- a/wcfsetup/install/files/lib/system/form/element/PasswordInputFormElement.class.php +++ b/wcfsetup/install/files/lib/system/form/element/PasswordInputFormElement.class.php @@ -18,11 +18,12 @@ class PasswordInputFormElement extends AbstractNamedFormElement { */ public function getHTML($formName) { return << +getErrorClass()}>
{$this->getDescription()} + {$this->getErrorField()}
HTML; diff --git a/wcfsetup/install/files/lib/system/form/element/TextInputFormElement.class.php b/wcfsetup/install/files/lib/system/form/element/TextInputFormElement.class.php index 20d32088a0..9f9441d760 100644 --- a/wcfsetup/install/files/lib/system/form/element/TextInputFormElement.class.php +++ b/wcfsetup/install/files/lib/system/form/element/TextInputFormElement.class.php @@ -18,11 +18,12 @@ class TextInputFormElement extends AbstractNamedFormElement { */ public function getHTML($formName) { return << +getErrorClass()}>
{$this->getDescription()} + {$this->getErrorField()}
HTML; diff --git a/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php b/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php index 6a84fa7aeb..0fb67211ba 100644 --- a/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php @@ -450,6 +450,13 @@ class PackageInstallationDispatcher { $packageDir = $document->getValue('packageDir'); if ($packageDir !== null) { + // validate package dir + if (file_exists(FileUtil::addLeadingSlash($packageDir) . 'global.php')) { + $document->setError('packageDir', WCF::getLanguage()->get('wcf.acp.package.packageDir.notAvailable')); + return null; + } + + // set package dir $packageEditor = new PackageEditor($this->getPackage()); $packageEditor->update(array( 'packageDir' => FileUtil::getRelativePath(WCF_DIR, $packageDir) diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 88c16baeed..9949a0bb4d 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -296,6 +296,7 @@ + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 9e2199cdf1..f15b345af6 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -296,6 +296,7 @@ +