Skip to content

Instantly share code, notes, and snippets.

@adatta02
Last active December 12, 2015 08:18
Show Gist options
  • Save adatta02/4743038 to your computer and use it in GitHub Desktop.
Save adatta02/4743038 to your computer and use it in GitHub Desktop.
<?php
public function getAllErrors($children, $template = true) {
$this->getAllFormErrors($children);
return $this->allErrors;
}
private function getAllFormErrors($children, $template = true) {
foreach ($children as $child) {
if ($child->hasErrors()) {
$vars = $child->createView()->getVars();
$errors = $child->getErrors();
foreach ($errors as $error) {
$this->allErrors[$vars["name"]][] = $this->convertFormErrorObjToString($error);
}
}
if ($child->hasChildren()) {
$this->getAllErrors($child);
}
}
}
private function convertFormErrorObjToString($error) {
$errorMessageTemplate = $error->getMessageTemplate();
foreach ($error->getMessageParameters() as $key => $value) {
$errorMessageTemplate = str_replace($key, $value, $errorMessageTemplate);
}
return $errorMessageTemplate;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment