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

[Form] Add shortcuts to set data class and validation groups #10327

Closed
wants to merge 1 commit into from

Conversation

stloyd
Copy link
Contributor

@stloyd stloyd commented Feb 25, 2014

Thanks to those simple shortcuts, when declaring forms as services, you can simply set the data class and/or validation groups.

Sample config:

<service id="acme.form.type.user" class="%acme.form.type.user.class%">
    <call method="setDataClass">
        <argument>%some_default_data_class%</argument>
    </call>
    <call method="setValidationGroups">
        <argument>%some_default_groups%</argument>
    </call>
    <tag name="form.type" alias="acme_user_form" />
</service>
Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes*
License MIT
Doc PR n/a (yet)

* - will fix if not =)

@arnolanglade
Copy link

👍

1 similar comment
@tadcka
Copy link
Contributor

tadcka commented Feb 26, 2014

+1

Thanks to those simple shortcuts, when declaring forms as services, you can simply set the data class and/or validation groups.

Sample config:
```
<service id="acme.form.type.user" class="%acme.form.type.user.class%">
    <call method="setDataClass">
        <argument>%some_default_data_class%</argument>
    </call>
    <call method="setValidationGroups">
        <argument>%some_default_groups%</argument>
    </call>
    <tag name="form.type" alias="acme_user_form" />
</service>
@webmozart
Copy link
Contributor

I see this a little problematic. How do we decide which options should support a setter and which shouldn't?

Why don't you pass these values to the constructor of your form type if you need this option?

@arnolanglade
Copy link

@webmozart : I understand the problematic, validation group and data classes are most common form options for our application. It can be useful when your form is related to a entity and you want to validate it (for a basic usage).

@stloyd stloyd added the Form label Mar 3, 2014
@stof
Copy link
Member

stof commented Mar 4, 2014

@stloyd This would not help here: you would need to have the setter in your own form type class, not in the form type (which will generally not be the type used by your form). Your sample code does not correspond to your PR

@webmozart
Copy link
Contributor

I don't want to merge this PR because of my aforementioned concerns. However, I think the underlying use case is valid and opened a new ticket for that: #10505

@webmozart webmozart closed this Mar 20, 2014
@stloyd stloyd deleted the patch-1 branch March 20, 2014 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants