public function buildView(FormView $view, FormInterface $form, array $options) { $knockout['enabled'] = $form->getAttribute('knockout'); if ($knockout['enabled'] === true) { $knockout['viewModel'] = array('name' => $form->getName(), 'fields' => $this->buildViewModelFields($form->getChildren()), 'bindings' => $this->buildViewModelBindings($form->getChildren()), 'collections' => $this->getCollections($form->getChildren(), $view)); } $view->set('knockout', $knockout); }
public static function getErrorMessages(FormInterface $form) { $errors = array(); foreach ($form->getErrors() as $key => $error) { $template = $error->getMessageTemplate(); $parameters = $error->getMessageParameters(); foreach ($parameters as $var => $value) { $template = str_replace($var, $value, $template); } $errors[$key] = $template; } if ($form->hasChildren()) { foreach ($form->getChildren() as $child) { if (!$child->isValid()) { $errors[$child->getName()] = self::getErrorMessages($child); } } } return $errors; }
private function buildNamePathMapping(FormInterface $form, array &$forms, $namePath = '') { $iterator = new VirtualFormAwareIterator($form->getChildren()); $iterator = new \RecursiveIteratorIterator($iterator); foreach ($iterator as $child) { $nestedNamePath = $namePath . '.' . $child->getName(); $forms[$nestedNamePath] = $child; if ($child->hasChildren()) { $this->buildNamePathMapping($child, $forms, $nestedNamePath); } } }
/** End Garantie Entity **/ protected function getErrorsAsString($fields, $class, $admin, \Symfony\Component\Form\FormInterface $form, $line, $level = 0, $field = '', $message = null) { $errors = array(); if ($form->getErrors()) { $one_view = array(); foreach ($form->getErrors() as $keys => $error) { if (!isset($one_view[$field][$line])) { $one_view[$field][$line] = true; $repeat = str_repeat(' ', $level); $label = isset($fields[$field]) ? '(' . (\PHPExcel_Cell::stringFromColumnIndex($fields[$field]) . ':' . $line) . ') ' : ''; $data = $form->getViewData(); if (is_array($data)) { $data = implode('-', $data); } if ($error->getMessageParameters()) { $data = implode($error->getMessageParameters()); } $errors[] = $repeat . 'VALUE : ' . $label . ($data ?: 'empty') . "\n"; $errors[] = $repeat . 'ERROR : ' . $error->getMessage() . "\n\n"; } } } foreach ($form->getChildren() as $field => $child) { if ($field == 'client') { continue; } if ($err = $this->getErrorsAsString($fields, $class, $admin, $child, $line, $level + 4, $field, null)) { $errors[] = $admin->trans('form.' . $class . '.' . $field) . "\n"; $errors[] = $err; } } if (!empty($message)) { $errors[] = $message; } return implode($errors); }