diff --git a/components/options_resolver.rst b/components/options_resolver.rst index 9a62f8581fa..d14ee678278 100644 --- a/components/options_resolver.rst +++ b/components/options_resolver.rst @@ -305,6 +305,26 @@ There is also an method, which you can use if you want to add an allowed value to the previously set allowed values. +If you need to add some more logic to the value validation process you can pass a callable +as an allowed value:: + + // ... + protected function setDefaultOptions(OptionsResolverInterface $resolver) + { + // ... + + $resolver->setAllowedValues(array( + 'transport' => function($value) { + return strpos($value, 'mail') !== false; + } + )); + } + +Note that using this together with addAllowedValues will not work. + +.. versionadded:: 2.5 + The callback support for allowed values was added in Symfony 2.5. + Configure allowed Types ~~~~~~~~~~~~~~~~~~~~~~~