Skip to content
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

Merged
merged 1 commit into from
Apr 9, 2018
Merged

Add ScalarToEnumTransformer #48

merged 1 commit into from
Apr 9, 2018

Conversation

ostrolucky
Copy link
Contributor

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.

Copy link
Member

@ogizanagi ogizanagi left a 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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- testThrowsExceptionIfNotFLaggedEnumInstance
+ testThrowsExceptionIfNotEnumInstance

@ostrolucky
Copy link
Contributor Author

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 :)

@ogizanagi
Copy link
Member

Thanks @ostrolucky.

@ogizanagi ogizanagi merged commit 9683e83 into Elao:master Apr 9, 2018
ogizanagi added a commit that referenced this pull request Apr 9, 2018
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
ogizanagi added a commit that referenced this pull request Apr 19, 2018
This PR was merged into the 1.x-dev branch.

Discussion
----------

Add EnumType choices_as_enum_values option

Following #48

Commits
-------

bc3fddb Add EnumType choices_as_enum_values option
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants