Skip to content

Instantly share code, notes, and snippets.

@desarrolla2
Created July 18, 2013 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save desarrolla2/6027758 to your computer and use it in GitHub Desktop.
Save desarrolla2/6027758 to your computer and use it in GitHub Desktop.
<?php
/**
* @param $form
* @return array
*/
private function getErrorsAsArray($form)
{
$errors = [];
foreach ($form->getErrors() as $error) {
$params = $error->getMessageParameters();
if (array_key_exists('{{ extra_fields }}', $params)) {
$formattedParams = explode(', ', str_replace("\"", "", $params['{{ extra_fields }}']));
$errors[] = "This form should not contain extra fields: " . implode(', ', $formattedParams);
continue;
}
$errors[] = $error->getMessage();
}
if ($form->hasChildren()) {
foreach ($form->getChildren() as $child) {
if (!$child->isValid()) {
array_merge($errors, $this->getErrorsAsArray($child);)
}
}
}
return $errors;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment