/** * Find all constraints for the given FormInterface. * * @param FormInterface $form * @return ConstraintCollection */ protected function findConstraints(FormInterface $form) { $constraints = new ConstraintCollection(); // Find constraints configured with the form $formConstraints = $form->getConfig()->getOption('constraints'); if (!empty($formConstraints)) { if (is_array($formConstraints)) { $constraints->addCollection(new ConstraintCollection($formConstraints)); } else { $constraints->add($formConstraints); } } // Find constraints bound by data if ($form->getConfig()->getMapped()) { $constraints->addCollection($this->constraintFinder->find($form)); } return $constraints; }