Skip to content

Commit 8ac6fed

Browse files
committed
feature #5093 Added a new best practices for custom form field types (javiereguiluz)
This PR was merged into the 2.3 branch. Discussion ---------- Added a new best practices for custom form field types | Q | A | ------------- | --- | Doc fix? | no | New docs? | yes | Applies to | all | Fixed tickets | #5077 Commits ------- 0696daf Fixed errors, typos and grammar issues. (I managed to fail at everything!) 8eb1240 Added a new best practices for custom form field types
2 parents 6b96470 + 0696daf commit 8ac6fed

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Diff for: best_practices/forms.rst

+18
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,21 @@ Second, we recommend using ``$form->isSubmitted()`` in the ``if`` statement
207207
for clarity. This isn't technically needed, since ``isValid()`` first calls
208208
``isSubmitted()``. But without this, the flow doesn't read well as it *looks*
209209
like the form is *always* processed (even on the GET request).
210+
211+
Custom Form Field Types
212+
-----------------------
213+
214+
.. best-practice::
215+
216+
Add the ``app_`` prefix to your custom form field types to avoid collisions.
217+
218+
Custom form field types inherit from the ``AbstractType`` class, which defines the
219+
``getName()`` method to configure the name of that form type. These names must
220+
be unique in the application.
221+
222+
If a custom form type uses the same name as any of the Symfony's built-in form
223+
types, it will override it. The same happens when the custom form type matches
224+
any of the types defined by the third-party bundles installed in your application.
225+
226+
Add the ``app_`` prefix to your custom form field types to avoid name collisions
227+
that can lead to hard to debug errors.

0 commit comments

Comments
 (0)