Skip to content

Commit 0a0bf4c

Browse files
committed
feature #3437 Add info about callback in options resolver (marekkalnik)
This PR was merged into the master branch. Discussion ---------- Add info about callback in options resolver | Q | A | ------------- | --- | Doc fix? | no | New docs? | yes (symfony/symfony#8375) | Applies to | 2.5+ | Fixed tickets | The documentation for the PR (pending) about validation callbacks in OptionsResolver. Commits ------- 8231230 Fix according to PR comments 94fe8dc Add info about callback in options resolver
2 parents c6ac96c + 8231230 commit 0a0bf4c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

components/options_resolver.rst

+23
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,29 @@ There is also an
305305
method, which you can use if you want to add an allowed value to the previously
306306
set allowed values.
307307

308+
.. versionadded:: 2.5
309+
310+
The callback support for allowed values was introduced in Symfony 2.5.
311+
312+
If you need to add some more logic to the value validation process, you can pass a callable
313+
as an allowed value::
314+
315+
// ...
316+
protected function setDefaultOptions(OptionsResolverInterface $resolver)
317+
{
318+
// ...
319+
320+
$resolver->setAllowedValues(array(
321+
'transport' => function($value) {
322+
return false !== strpos($value, 'mail');
323+
},
324+
));
325+
}
326+
327+
.. caution::
328+
329+
Note that using this together with ``addAllowedValues`` will not work.
330+
308331
Configure allowed Types
309332
~~~~~~~~~~~~~~~~~~~~~~~
310333

0 commit comments

Comments
 (0)