Skip to content

Commit

Permalink
feature #5093 Added a new best practices for custom form field types …
Browse files Browse the repository at this point in the history
…(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
  • Loading branch information
weaverryan committed Mar 24, 2015
2 parents 6b96470 + 0696daf commit 8ac6fed
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions best_practices/forms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 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 your application.

Add the ``app_`` prefix to your custom form field types to avoid name collisions
that can lead to hard to debug errors.

0 comments on commit 8ac6fed

Please sign in to comment.