8000 Some improvements on validation_groups option · symfony/symfony-docs@6185a26 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6185a26

Browse files
author
naitsirch
committed
Some improvements on validation_groups option
1 parent 11e85cb commit 6185a26

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

reference/forms/types/options/validation_groups.rst.inc

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ groups will be used by the validator.
88

99
For ``null`` the validator will just use the ``Default`` group.
1010

11-
If you specify the groups as array or string they will used by the validator
12-
as they are::
11+
If you specify the groups as an array or string they will be used by the
12+
validator as they are::
1313

1414
public function configureOptions(OptionsResolver $resolver)
1515
{
@@ -22,7 +22,7 @@ This is equivalent to passing the group as array::
2222

2323
'validation_groups' => array('Registration'),
2424

25-
The form's data will be :doc:`validated agains all groups </form/validation_groups>`.
25+
The form's data will be :doc:`validated against all given groups </form/validation_groups>`.
2626

2727
If the validation groups depend on the form's data a callable may be passed to
2828
the option. Symfony will then pass the form when calling it::
@@ -36,21 +36,12 @@ the option. Symfony will then pass the form when calling it::
3636
$resolver->setDefaults(array(
3737
'validation_groups' => function (FormInterface $form) {
3838
$entity = $form->getData();
39-
return $entity->getValidationGroups();
39+
40+
return $entity->isUser() ? array('User') : array('Company');
4041
},
4142
));
4243
}
4344

44-
The class that the form is used for may look like this::
45-
46-
class Account
47-
{
48-
public function getValidationGroups()
49-
{
50-
return $this->isUser() ? array('User') : array('Company');
51-
}
52-
}
53-
5445
.. seealso::
5546

5647
You can read more about this in :doc:`/form/data_based_validation`.
@@ -64,7 +55,7 @@ The class that the form is used for may look like this::
6455
If you need advanced logic to determine the validation groups have
6556
a look at :doc:`/form/validation_group_service_resolver`.
6657

67-
In some cases, you want to validate your groups by steps. To do this, you
58+
In some cases, you want to validate your groups step by step. To do this, you
6859
can pass a :class:`Symfony\\Component\\Validator\\Constraints\\GroupSequence`
6960
to this option. This enables you to validate against multiple groups,
7061
like when you pass multiple groups in an array, but with the difference that

0 commit comments

Comments
 (0)
0