Created
July 18, 2013 08:44
-
-
Save desarrolla2/6027758 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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