-
-
Notifications
You must be signed in to change notification settings - Fork 27
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 ScalarToEnumTransformer #48
Conversation
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.
Great! Thanks for this.
But would it be possible to integrate this in the EnumType
, through a new choices_as_enum_values
(or whatever) option? In another PR?
* @expectedException \Symfony\Component\Form\Exception\InvalidArgumentException | ||
* @expectedExceptionMessage "stdClass" is not an instance of "Elao\Enum\EnumInterface" | ||
*/ | ||
public function testThrowsExceptionIfNotFLaggedEnumInstance() |
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.
- testThrowsExceptionIfNotFLaggedEnumInstance
+ testThrowsExceptionIfNotEnumInstance
Of course. Just didn't want to spend more time on figuring out how to integrate this there. It can be used standalone for now. We can integrate it later :) |
Thanks @ostrolucky. |
This PR was merged into the 1.x-dev branch. Discussion ---------- Add ScalarToEnumTransformer I found EnumType very limiting, because it enforces either Enum instances inside choices, or scalar value as output. This is inconvenient, because it's common to have scalar key-value pairs stored as an array in class constant. Storing there objects is not possible. So, this transformer is meant to be used in conjunction with normal ChoiceType and scalar choices. Commits ------- 9683e83 Add ScalarToEnumTransformer
I found EnumType very limiting, because it enforces either Enum instances inside choices, or scalar value as output.
This is inconvenient, because it's common to have scalar key-value pairs stored as an array in class constant. Storing there objects is not possible.
So, this transformer is meant to be used in conjunction with normal ChoiceType and scalar choices.