Skip to content

Commit

Permalink
Merge branch '6.1' into 6.2
Browse files Browse the repository at this point in the history
* 6.1:
  [Form] Reorder and remove duplicate methods explanation for form type
  Add paragraph about symfony-cli workers
  • Loading branch information
javiereguiluz committed Nov 3, 2022
2 parents 739daaf + 0a93d6b commit 5ec30fa
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
27 changes: 11 additions & 16 deletions form/create_custom_field_type.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,39 +119,34 @@ These are the most important methods that a form type class can define:

.. _form-type-methods-explanation:

``getParent()``
When returning a (fully-qualified) class name here, Symfony will call each
method of that type (i.e. ``buildForm()``, ``buildView()``, etc.) and all its
type extensions, before calling the corresponding method of your custom type.
This is probably a good idea if you're just changing some details of an
existing type. To start from scratch, omit ``getParent()``.

``buildForm()``
It adds and configures other types into this type. It's the same method used
when :ref:`creating Symfony form classes <creating-forms-in-classes>`.

``buildView()``
It sets any extra variables you'll need when rendering the field in a template.

``configureOptions()``
It defines the options configurable when using the form type, which are also
the options that can be used in ``buildForm()`` and ``buildView()``
methods. Options are inherited from parent types and parent type
extensions, but you can create any custom option you need.

``finishView()``
This method allows to modify the "view" of any rendered widget. This is useful
if your form type consists of many fields, or contains a type that produces
many HTML elements (e.g. ``ChoiceType``). For any other use case, it's
recommended to use ``buildView()`` instead.

``configureOptions()``
It defines the options configurable when using the form type, which are also
the options that can be used in ``buildForm()`` and ``buildView()``
methods. Options are inherited from parent types and parent type
extensions, but you can create any custom option you need.

``getParent()``
If your custom type is based on another type (i.e. they share some
functionality) add this method to return the fully-qualified class name
functionality), add this method to return the fully-qualified class name
of that original type. Do not use PHP inheritance for this.
Symfony will call all the form type methods (``buildForm()``,
``buildView()``, etc.) of the parent type and it will call all its type
extensions before calling the ones defined in your custom type.
``buildView()``, etc.) and type extensions of the parent before
calling the ones defined in your custom type.

Otherwise, if your custom type is build from scratch, you can omit ``getParent()``.

By default, the ``AbstractType`` class returns the generic
:class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\FormType`
Expand Down
25 changes: 25 additions & 0 deletions setup/symfony_server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,31 @@ server provides a ``run`` command to wrap them as follows:
# stop the web server (and all the associated commands) when you are finished
$ symfony server:stop
Configuring Workers
-------------------

If you like some processes to start automatically, along with the webserver
(``symfony server:start``), add a configuration file to your project:

.. code-block:: yaml
# .symfony.local.yaml
workers:
# built-in command that builds and watches front-end assets
# yarn_encore_watch:
# cmd: ['yarn', 'encore', 'dev', '--watch']
yarn_encore_watch: ~
# built-in command that starts messenger consumer
# messenger_consume_async:
# cmd: ['symfony', 'console', 'messenger:consume', 'async']
# watch: ['config', 'src', 'templates', 'vendor']
messenger_consume_async: ~
# you can also add your own custom commands
build_spa:
cmd: ['yarn', '--cwd', './spa/', 'dev']
.. _symfony-server-docker:

Docker Integration
Expand Down

0 comments on commit 5ec30fa

Please sign in to comment.