Skip to content

[Form] vague/incorrect information in article for dynamic form modification #6376

@thedamnedrhino

Description

@thedamnedrhino

There is this paragraph inside the cookbook entry for dynamic form modification:

You might wonder, now that you have access to the User (through the token storage), why not just use it directly in buildForm and omit the event listener? This is because doing so in the buildForm method would result in the whole form type being modified and not just this one form instance. This may not usually be a problem, but technically a single form type could be used on a single request to create many forms or fields.

First of all adding a listener inside the buildForm method of a form type, will cause that listener to be added to all instances of that form type not just one instance.
Also, I think in that specific example adding the field directly in buildForm will result in the exact same Form. Because buildForm is called for every created form of that type separately, the only scenario in which these two approaches might produce different results, consists of the TokenStorage object changing it's state between buildForm is called on the FormType and setData is is called on the Form which is highly unlikely. If there is some other scenario that I'm missing, it should be clarified with an example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FormhasPRA Pull Request has already been submitted for this issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions