symfony/symfony-docs — Issue #896: [Form] Adding constraints to a non-entity related form fails
Author: jcrombez
Created: 2011-12-01 10:15:13+00:00
State: open

Hello,

I think i found a problem in Symfony Form (2.0.6).

First, it's more a documentation issue but still : http://symfony.com/doc/2.0/book/forms.html#adding-validation

In the example, there is no return $options, it was my first problem in trying to add constraints to my form. I'm not sure of the whole correction so i didn't pull-requested anything in the symfony-doc repo yet.

Second, a more serious problem (i think at least), when FormFactory process the options, it failed to array_replace the Constraints Collection :

The code

public function getDefaultOptions(array $options)
{
$collectionConstraint = new Collection(array(
'time' => new Choice(array(
'choices' => $this->times
))
));

return $options['validation_constraint'] = $collectionConstraint;
}

The error

Warning: array_replace(): Argument #1 is not an array in /path/to/my/project/vendor/symfony/src/Symfony/Component/Form/FormFactory.php line 236

Argument #1 being the Constraints Collection.