Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Form] Added documentation for Form Events#3704

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
weaverryan merged 1 commit intosymfony:2.3fromcsarrazi:components/form/form_events
May 6, 2014
Merged

[Form] Added documentation for Form Events#3704

weaverryan merged 1 commit intosymfony:2.3fromcsarrazi:components/form/form_events
May 6, 2014

Conversation

csarrazi
Copy link
Contributor

QA
Doc fix?no
New docs?yes
Applies to>=2.3
Fixed ticketsDunno

Added initial documentation for Form Events:

  • List of events
  • Use cases for each event
  • Description of the events workflow
  • Flow charts for illustration
  • Registering event listeners or subscribers in a form
  • Describing the data available for each event

@csarrazi
Copy link
ContributorAuthor

This is an initial WIP. It is far from being finished, but the final goal is to completely describe Form Events in the component's documentation, and not only in the cookbook, which doesn't formally explains form events.

@wouterj
Copy link
Member

Wow, thank you!

Please note that there is already an article about form events in the cookbook:http://symfony.com/doc/current/cookbook/form/dynamic_form_modification.html You might be able to get some usefull things from it. At least, you should remove all things you put in the components article from that cookbook article and add a reference (or multiple references) to this new article.

In the end, we should have a components article telling you everything you need to know about Form Events and a cookbook article which gives you a short introduction and framework specific things. If you do not want to do this, someone of the community can do it after this one is merged. :)

Again, big thanks for getting this roling!

The Form component provides a structured process letting you customize your
forms, by making use of the EventDispatcher. Using form events, you may
modify information or fields at different points of time. From the form's
pre-population to the submission of the request's data.
Copy link
Member

Choose a reason for hiding this comment

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

This should not be indented (that something specific for the component introduction articles, I don't know why we did that...)

@csarrazi
Copy link
ContributorAuthor

Done. Also added a bit of code for adding a form event listener and a form event subscriber when using the form builder.

Form Events
===========

The Form component provides a structured process letting you customize your
Copy link
Contributor

Choose a reason for hiding this comment

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

to let you customize

@xabbuh
Copy link
Member

👍 Great article! I really like it!


The ``PRE_SET_DATA`` event is dispatched when
:method:`Form::setData() <Symfony\\Component\\Form\\Form::setData>`
is called. It can be used to:
Copy link
Member

Choose a reason for hiding this comment

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

this is somewhat duplicating the previous paragraph. I think we have to tell when it happends, like: "ThePRE_SET_DATA event is dispatched in the beginning of theForm::setData() method."


The ``SUBMIT`` event is dispatched just before the
:method:`Form::submit() <Symfony\\Component\\Form\\Form::submit>` method
transforms back the normalized data to the model and view data.
Copy link
Member

Choose a reason for hiding this comment

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

this is wrong. the normalized data is not transformed back to the view data, as it was just buildfrom the submitted view data

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Actually, it is. Seehttps://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Form.php#L632

// Synchronize representations - must not change the content!$modelData = $this->normToModel($normData);$viewData = $this->normToView($normData);

@csarrazi
Copy link
ContributorAuthor

Rebased commits once again.

@weaverryan
Copy link
Member

WOW, this is really incredible! Great great work!

I have one thought. There are basically 2 sections to this entry: (A) explaining the form lifecycle and different events and (B) how to actually register event listeners/subscribers. I think we should change their order: explain how to register listeners first, then explain the event second.

The reason is that I realized in the beginning (where we talk about the different events), we're talking about how to get at form data and the event object, as well as referring to events simply as SUBMIT, before really explaining that these are constants on FormEvents. If you reverse the order of these sections, I think it's an even better entry.

What do you guys think? After this issue (and I left one other small comment), this is ready to merge! Great work to everyone!

@csarrazi
Copy link
ContributorAuthor

Hum, not sure. I just made the change locally, and it actually feels weird talking about form event listeners and subscribers before actually describing the events and the workflow. If we invert the sections, we need to rephrase a few things so it feels fluid.
In any case, I can also rephrase the sections of the documentation to refer toFormEvents::{EVENT_NAME} instead of simply{EVENT_NAME}.

@weaverryan
Copy link
Member

Ok, let's keep it how it is - but yea, I likeFormEvents::{EVENT_NAME} better, and we can also add a quick note to the top with a link that points to the second section on usage. A very very quick example usage at the top of the chapter (not really doing anything, just showing the registration of an anonymous function on some form event, and the arguments of that callback) might be plenty to give people enough idea of how this works before explaining the events.

Thanks for checking it out :)

@csarrazi
Copy link
ContributorAuthor

Done. And also rebased the commits.

@csarrazi
Copy link
ContributorAuthor

Well then, I guess it should be ready for merge, now!
What do you think about it now,@weaverryan? :)

validate the CSRF token.

B) The ``FormEvents::SUBMIT`` Event
.......................
Copy link
Member

Choose a reason for hiding this comment

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

The underline doesn't match the title length.

@csarrazi
Copy link
ContributorAuthor

Updated

@csarrazi
Copy link
ContributorAuthor

Fixed issue with travis build (underline too short)

@csarrazi
Copy link
ContributorAuthor

ping@weaverryan

@wouterj
Copy link
Member

@csarrazi this PR is now ready. It'll be merged once@weaverryan has time to review and merge it. Since this PR add lots of stuff, it can take a little bit longer than smaller PRs. But don't worry, this great PR will never be missed by us :)

@xabbuh
Copy link
Member

@csarrazi But you can remove the [WIP] tag from the title for now. So, it's more obvious that the PR is finished. :)

@csarrazicsarrazi changed the title[WIP] [Form] Added documentation for Form Events[Form] Added documentation for Form EventsApr 8, 2014
@csarrazi
Copy link
ContributorAuthor

Thanks! I removed the [WIP] tag :)

use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;

class AddEmailFieldListener implements EventSubscriberInterface
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe change the name to AddEmailFieldSubscriber

Copy link
Member

Choose a reason for hiding this comment

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

Using listener for this is a Symfony convention, so let's stick with it (although I tend to agree with you that Subscriber is a better naming)

@csarrazi
Copy link
ContributorAuthor

bump@weaverryan ! :)

different steps of the workflow: from the population of the form to the
submission of the data from the request.

Registering an event listener very easy using the Form component.
Copy link
Contributor

Choose a reason for hiding this comment

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

is very easy

@aitboudad
Copy link
Contributor

👍

Added initial documentation for Form Events:* List of events* Use cases for each event* Description of the events workflow* Flow charts for illustrationUpdated PR with comments from@wouterj and@mykiwiTook into account@cordoval's feedbackAdditional improvements* Added more examples from the Form component's code* Moved the cookbook's 'register a subscriber using a callable' section into the form events documentationTook into account@xabbuh's feedbackFixed missing new lineRemoved superfluous comma.Updated from feedbackMoved the list of events down in the listener and subscriber section* Formatted the list as a table, exposing the constant values;* Added references to the form event information table;* Added caution sections for actions that should prevented while in each event.Added the form_events link in the components map file, a.k.a. 'Added the missing link'Added missing newlinesAdded cross-reference in the form events cookbookUpdated based on Luis' feedbackAdded tables describing the form and event values:* Model data* Normalized data* View data* Event dataSmall fixesUpdated a few wordings to make them more clearChanged important directive to cautionRemoved sidebar section about form extensions.Renamed ``{EVENT}`` to ``FormEvents::{EVENT}``, and added code snippetLast small changesFixed underline too short
@weaverryan
Copy link
Member

Sorry for getting the merge slowly - this is a truly wonderful effort and entry. I'm looking forward to showing this resource to people who are working with form events. Great work to you Charles and everyone :). Thanks!

@weaverryanweaverryan merged commit98de95a intosymfony:2.3May 6, 2014
weaverryan added a commit that referenced this pull requestMay 6, 2014
This PR was merged into the 2.3 branch.Discussion----------[Form] Added documentation for Form Events| Q             | A| ------------- | ---| Doc fix?      | no| New docs?     | yes| Applies to    | >=2.3| Fixed tickets | DunnoAdded initial documentation for Form Events:* List of events* Use cases for each event* Description of the events workflow* Flow charts for illustration* Registering event listeners or subscribers in a form* Describing the data available for each eventCommits-------98de95a [Form] Added documentation for Form Events
@csarrazicsarrazi deleted the components/form/form_events branchMay 6, 2014 12:23
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

11 participants
@csarrazi@wouterj@xabbuh@cordoval@saro0h@weaverryan@aitboudad@mykiwi@gilles-g@stof@ggam

[8]ページ先頭

©2009-2025 Movatter.jp