merged branch sellingsource/EXPOSE_FORM_VALIDATORS (PR #2983)

Commits
-------

601d462 [Form] Added getValidators() to Form class

Discussion
----------

[Form] Added getValidators() to Form class

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes

I am working implementing client side validation in a bundle that adds validation rules via a form builder. I am currently unable to pull the validators from the Form class which is making the implementation incredibly difficult.

I noticed that the transformers are currently exposed and based on some feedback I got on IRC I am guessing these weren't exposed simply because no one needed them at the time.

---------------------------------------------------------------------------

by mlively at 2011-12-28T20:54:41Z

Side note: It would be incredibly helpful to have this in the current branch of symfony. I implemented it on master because it is a new feature, but I would be more than happy to patch it into 2.0 if you would like.

---------------------------------------------------------------------------

by canni at 2012-01-11T10:15:46Z

👍

As this is new feature it cannot fit into 2.0 series, but 2.1 is just few clicks ahead, maybe this feature will  fit into  ;)

---------------------------------------------------------------------------

by bschussek at 2012-01-31T08:23:05Z

ping @fabpot
👍

---------------------------------------------------------------------------

by stof at 2012-01-31T08:51:26Z

@mlively could you rebase your branch ? it conflicts with the current master

---------------------------------------------------------------------------

by mlively at 2012-01-31T21:38:39Z

Yes, I can do that might be later today.
This commit is contained in:
Fabien Potencier 2012-02-02 09:36:07 +01:00
commit 1c3e6c2cb2
2 changed files with 20 additions and 0 deletions

View File

@ -787,6 +787,16 @@ class Form implements \IteratorAggregate, FormInterface
return $this->clientTransformers;
}
/**
* Returns the Validators
*
* @return array An array of FormValidatorInterface
*/
public function getValidators()
{
return $this->validators;
}
/**
* Returns all children in this group.
*

View File

@ -1166,6 +1166,16 @@ class FormTest extends \PHPUnit_Framework_TestCase
->getForm();
}
public function testGetValidatorsReturnsValidators()
{
$validator = $this->getFormValidator();
$form = $this->getBuilder()
->addValidator($validator)
->getForm();
$this->assertEquals(array($validator), $form->getValidators());
}
protected function getBuilder($name = 'name', EventDispatcherInterface $dispatcher = null)
{
return new FormBuilder($name, $this->factory, $dispatcher ?: $this->dispatcher);