8000 Merge branch 'form-errors' · mitchellzen/symfony@3ad395c · GitHub
[go: up one dir, main page]

Skip to content

Commit 3ad395c

Browse files
committed
Merge branch 'form-errors'
* form-errors: [Form] added a method to help debugging forms (Form::getAllErrorsAsString())
2 parents 07e5690 + 5dccc97 commit 3ad395c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/Symfony/Component/Form/Form.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,36 @@ public function getErrors()
720720
return $this->errors;
721721
}
722722

723+
/**
724+
* Returns a string representation of all form errors (including children errors).
725+
*
726+
* This method should only be used to help debug a form.
727+
*
728+
* @param integer $level The indentation level (used internally)
729+
*
730+
* @return string A string representation of all errors
731+
*/
732+
public function getErrorsAsString($level = 0)
733+
{
734+
$errors = '';
735+
foreach ($this->errors as $error) {
736+
$errors .= str_repeat(' ', $level).'ERROR: '.$error->getMessageTemplate()."\n";
737+
}
738+
739+
if ($this->hasChildren()) {
740+
foreach ($this->children as $key => $child) {
741+
$errors .= str_repeat(' ', $level).$key.":\n";
742+
if ($err = $child->getErrorsAsString($level + 4)) {
743+
$errors .= $err;
744+
} else {
745+
$errors .= str_repeat(' ', $level + 4)."No errors\n";
746+
}
747+
}
748+
}
749+
750+
return $errors;
751+
}
752+
723753
/**
724754
* Returns the DataTransformers.
725755
*

0 commit comments

Comments
 (0)
0