Skip to content

[Cookbook][Forms] Add how to generic form type extension #5154

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

Closed

Conversation

lemoinem
Copy link
Contributor

@lemoinem lemoinem commented Apr 7, 2015

I spent almost 15 minutes trying to find how to create a generic Form Type Extension.

I found the doc in http://symfony.com/doc/current/reference/dic_tags.html#form-type-extension and http://stackoverflow.com/questions/24307849/how-to-overwrite-all-symfony2-form-types-and-add-some-property-in-version-2-2 (in which a comment specifies the answer for Symfony 2.3+)

The cookbook article mentions it's possible, but not how to do it.
This PR aims to add the information directly in the cookbook article in order to make it easier to find.

@@ -129,6 +129,9 @@ The ``alias`` key of the tag is the type of field that this extension should
be applied to. In your case, as you want to extend the ``file`` field type,
you will use ``file`` as an alias.

If you want to create a generic feature, applied to all field types, simply
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't "generic feature" be "generic extension"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I followed the vocabulary used in the first section list which says

You want to add a generic feature to several types (such as adding a "help" text to every field type);

(original emphasis)

But if you still think extension would be a better word, I will be happy to amend my commit.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, what about removing it completely:

If you want to apply the extension to all field types, you can specify form as alias and value returned by getExtendedType().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I liked to have the original vocabulary or at least the word "generic" to make it searchable. But I like your formulation too and its location in the page should be enough.

New commit on its way.

@wouterj
Copy link
Member

wouterj commented Apr 7, 2015

Thanks a lot! I've left one minor comment, but overall I like this addition,

… appropriate doc (got it from reference/dic_tags.html#form-type-extension)
@lemoinem lemoinem force-pushed the add-how-to-generic-form-type-extension branch from 8365d36 to 1b83b95 Compare April 7, 2015 16:01
@stof
Copy link
Member

stof commented Apr 7, 2015

Note that returning form does not magically apply it to all form types. And I can even tell you it does not do that: it won't be applied for buttons.
The reason returning form makes it quite generic is because all form types except buttons (and form itself of course) inherit (directly or no) from form. Type extensions are applied based on the type hierarchy, just like the configuration done by types themselves

@lemoinem
Copy link
Contributor Author

lemoinem commented Apr 7, 2015

Then what would be the configuration to apply an extension to all types?
The current documentation certainly mentions it's possible and it seems like a very reasonable feature to have.

If a code PR is required for this, I'm certainly ready to code and open one since I need the feature. Would you be interested by that?

@lemoinem
Copy link
Contributor Author

lemoinem commented May 4, 2015

The PR to fix the code and restore the feature has been rejected.
I'll propose a new PR to fix the documentation soon...

@lemoinem lemoinem closed this May 4, 2015
xabbuh added a commit that referenced this pull request Sep 23, 2015
…nem)

This PR was squashed before being merged into the 2.3 branch (closes #5227).

Discussion
----------

[Cookbook] Fix doc on Generic Form Type Extensions

| Q             | A
| ------------- | ---
| Doc fix?      | yes
| New docs?     | no
| Applies to    | >=2.3
| Fixed tickets | N/A

Follow up on #5154 (Sorry the first one didn't use the PR Template BTW) and symfony/symfony#14456.

I cleaned up the reference on DIC Tags, I think referring to the cookbook article prevents duplicating documentation (and taking the risk it will get out of date or inconsistent later on, as it did).

Then I removed the mention of Generic FTE at the top of the cookbook article. Since the feature doesn't exists anymore, I think it's better to leave it aside. I simply mentioned why it's impossible in a short last paragraph at the end of the CB entry.

I kept both commit unsquashed because they seemed to address different enough concerns. But I will squash them upon request if you think it's necessary.

Commits
-------

a6bc497 [Cookbook] Fix doc on Generic Form Type Extensions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants