Skip to content

Block prefix ambiguity #6646

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions book/forms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ your controller::
'form' => $form->createView(),
));
}

.. caution::

Be aware that the ``createView()`` method should be called *after* ``handleRequest``
Expand Down Expand Up @@ -686,7 +686,7 @@ the documentation for each type.
is left blank. If you don't want this behavior, either
:ref:`disable HTML5 validation <book-forms-html5-validation-disable>`
or set the ``required`` option on your field to ``false``::

->add('dueDate', 'date', array(
'widget' => 'single_text',
'required' => false
Expand Down Expand Up @@ -1128,6 +1128,24 @@ the choice is ultimately up to you.
));
}

.. caution::

When the name of your form class matches any registered field type that has
Copy link
Member

Choose a reason for hiding this comment

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

[...] form type class [...]

its own theme fragment, your form won't be rendered correctly. A form
Copy link
Member

Choose a reason for hiding this comment

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

A form type named [...]

``AppBundle\\Form\\Type\\PasswordType`` to change a user password for
instance will be mistaken for the built-in ``PasswordType`` field type and
will be rendered incorrectly using the ``password_widget`` theme fragment.
You can still use the class name of your choice by overriding the
``getBlockPrefix`` method of your form class::

public function getBlockPrefix()
{
return 'app_bundle_password';
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just app_password?

}

Read the ":doc:`/cookbook/form/create_custom_field_type`" chapter for more
information.

.. tip::

When mapping forms to objects, all fields are mapped. Any fields on the
Expand Down