-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add info about callback in options resolver #3437
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be return false !== strpos($value, 'mail'); to be consistent with the Symfony coding standards. |
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing comma after the brace |
||
)); | ||
} | ||
|
||
Note that using this together with addAllowedValues will not work. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. addAllowedValues should be placed in an inline code block, put it in double backticks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Imho this should be put in a note or caution block. |
||
|
||
.. versionadded:: 2.5 | ||
The callback support for allowed values was added in Symfony 2.5. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was introduced in Symfony 2.5. And this message should be placed before this addition, instead of after it imo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
Configure allowed Types | ||
~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[....] process, you can [...]