From 8eb1240c6f937ecf44a959254ede1ac0d0cee228 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Thu, 19 Mar 2015 10:23:15 +0100 Subject: [PATCH 1/2] Added a new best practices for custom form field types --- best_practices/forms.rst | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/best_practices/forms.rst b/best_practices/forms.rst index d72d189ccfb..0b3514beaab 100644 --- a/best_practices/forms.rst +++ b/best_practices/forms.rst @@ -207,3 +207,21 @@ Second, we recommend using ``$form->isSubmitted()`` in the ``if`` statement for clarity. This isn't technically needed, since ``isValid()`` first calls ``isSubmitted()``. But without this, the flow doesn't read well as it *looks* like the form is *always* processed (even on the GET request). + +Custom Form Field Types +----------------------- + +.. best-practice:: + + Add the ``app.`` prefix to your custom form field types to avoid collisions. + +Custom form field types extend from the ``AbstractType`` class, which defines the +``getName()`` method to configure the name of that form type. These names must +be unique in the application. + +If a custom form type uses the same name as any of the Symfony's built-in form +types, it will override it. The same happens when the custom form type matches +any of the types defined by the third-party bundles installed in you application. + +Add the ``app.`` prefix to your custom form field types to avoid name collisions +that can lead to hard to debug errors. From 0696daf554eec16ac2281873df3246dde898adca Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Thu, 19 Mar 2015 16:20:39 +0100 Subject: [PATCH 2/2] Fixed errors, typos and grammar issues. (I managed to fail at everything!) --- best_practices/forms.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/best_practices/forms.rst b/best_practices/forms.rst index 0b3514beaab..3d47e30490b 100644 --- a/best_practices/forms.rst +++ b/best_practices/forms.rst @@ -213,15 +213,15 @@ Custom Form Field Types .. best-practice:: - Add the ``app.`` prefix to your custom form field types to avoid collisions. + Add the ``app_`` prefix to your custom form field types to avoid collisions. -Custom form field types extend from the ``AbstractType`` class, which defines the +Custom form field types inherit from the ``AbstractType`` class, which defines the ``getName()`` method to configure the name of that form type. These names must be unique in the application. If a custom form type uses the same name as any of the Symfony's built-in form types, it will override it. The same happens when the custom form type matches -any of the types defined by the third-party bundles installed in you application. +any of the types defined by the third-party bundles installed in your application. -Add the ``app.`` prefix to your custom form field types to avoid name collisions +Add the ``app_`` prefix to your custom form field types to avoid name collisions that can lead to hard to debug errors.