/** * @test */ public function buildViewRootForm() { $this->configureFormRoot(); $this->form->count()->shouldBeCalled()->willReturn(2); $extension = $this->createExtension(); $this->buildView($extension); $attributes = $this->view->vars['attr']; $this->assertArrayHasKey('novalidate', $attributes); $this->assertTrue($attributes['novalidate']); $this->assertArrayHasKey('data-parsley-validate', $attributes); $this->assertTrue($attributes['data-parsley-validate']); $this->assertArrayNotHasKey('data-parsley-trigger', $attributes); }
/** * {@inheritdoc} * * @param FormView $view * @param FormInterface $form * @param array $options */ public function buildView(FormView $view, FormInterface $form, array $options) { if ($form->count() == 0) { return; } array_map(array($this, 'validateButton'), $form->all()); }
/** * Returns an array with form fields errors * * @param FormInterface $form * @param bool|false $useLabels * @param array $errors * @return array */ public function getErrorMessages(FormInterface $form, $useLabels = false, $errors = array()) { if ($form->count() > 0) { foreach ($form->all() as $child) { if (!$child->isValid()) { $errors = $this->getErrorMessages($child, $useLabels, $errors); } } } foreach ($form->getErrors() as $error) { if ($useLabels) { $fieldNameData = $this->getErrorFormLabel($form); } else { $fieldNameData = $this->getErrorFormId($form); } $fieldName = $fieldNameData; if ($useLabels) { /** * @ignore */ $fieldName = $this->translator->trans($fieldNameData['label'], array(), $fieldNameData['domain']); } $errors[$fieldName] = $error->getMessage(); } return $errors; }
protected function isExpanded(FormInterface $form) { if (0 === $form->count()) { return false; } $innerType = $form->getConfig()->getType()->getInnerType(); if (0 === strpos(get_class($innerType), 'Symfony')) { return false; } return true; }
/** * Returns the form's data like $form->submit() expects it * * @param FormInterface $form * @return array */ protected function unbind(FormInterface $form) { if ($form->count() > 0) { $ary = array(); foreach ($form->all() as $name => $child) { $value = $this->unbind($child); if (null !== $value || (is_array($value) || $value instanceof Collection) && count($value) > 0) { $ary[$name] = $value; } } return $ary; } else { $data = $form->getViewData(); return $data instanceof Collection ? $data->toArray() : $data; } }
private static function addChildErrors(FormInterface $parent, &$errors, $path = '') { if ($parent->count() == 0) { return; } foreach ($parent as $child) { if ($path == '') { $childPath = $child->getName(); } else { $childPath = $path . '.' . $child->getName(); } if ($child->isValid()) { continue; } $childErrors = array(); foreach ($child->getErrors() as $key => $error) { $childErrors[$key] = $error->getMessage(); } if (count($childErrors) > 0) { $errors[$childPath] = $childErrors; } self::addChildErrors($child, $errors, $childPath); } }