New in Symfony 3.4: debug:form command
October 16, 2017 • Published by Javier Eguiluz
Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.
One of the best features of Symfony is the amount of debugging tools available
so you can quickly fix any problem. We're continuously improving those tools and
that's why in Symfony 3.4 we added a new command called debug:form
.
When executed without arguments, the command lists all built-in types, services types, type extensions and guessers available in your application. For example, if you execute it in the Symfony Demo application:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
$ ./bin/console debug:form
Built-in form types (Symfony\Component\Form\Extension\Core\Type)
----------------------------------------------------------------
BirthdayType, ButtonType, CheckboxType, ChoiceType, CollectionType
ColorType, CountryType, CurrencyType, DateIntervalType, DateTimeType
...
TextareaType, TimeType, TimezoneType, UrlType
Service form types
------------------
* App\Form\CommentType
* App\Form\PostType
* App\Form\Type\DateTimePickerType
* App\Form\Type\TagsInputType
* Symfony\Bridge\Doctrine\Form\Type\EntityType
Type extensions
---------------
* Symfony\Component\Form\Extension\Csrf\Type\FormTypeCsrfExtension
* Symfony\Component\Form\Extension\DataCollector\Type\DataCollectorTypeExtension
* ...
* Symfony\Component\Form\Extension\Validator\Type\UploadValidatorExtension
Type guessers
-------------
* Symfony\Bridge\Doctrine\Form\DoctrineOrmTypeGuesser
* Symfony\Component\Form\Extension\Validator\ValidatorTypeGuesser
If you pass a form type as the first argument, the command shows the options defined for that type, its parents and its extensions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
$ ./bin/console debug:form 'App\Form\PostType'
# if the type class is unambiguous, you don't need to pass the FQCN:
# ./bin/console debug:form PostType
App\Form\PostType (Block prefix: "post")
========================================
-------------------- ------------------------- ----------------------------
Overridden options Parent options Extension options
-------------------- ------------------------- ----------------------------
FormType FormType FormTypeValidatorExtension
-------------------- ------------------------- ----------------------------
data_class action allow_extra_fields
attr constraints
auto_initialize error_mapping
block_name extra_fields_message
by_reference invalid_message
compound invalid_message_parameters
data validation_groups
disabled
empty_data FormTypeCsrfExtension
error_bubbling ----------------------------
inherit_data csrf_field_name
label csrf_message
label_attr csrf_protection
label_format csrf_token_id
mapped csrf_token_manager
method
post_max_size_message
property_path
required
translation_domain
trim
upload_max_size_message
-------------------- ------------------------- ----------------------------
Parent types
------------
* Symfony\Component\Form\Extension\Core\Type\FormType
Type extensions
---------------
* Symfony\Component\Form\Extension\HttpFoundation\Type\FormTypeHttpFoundationExtension
* Symfony\Component\Form\Extension\Validator\Type\FormTypeValidatorExtension
* Symfony\Component\Form\Extension\Validator\Type\UploadValidatorExtension
* Symfony\Component\Form\Extension\Csrf\Type\FormTypeCsrfExtension
* Symfony\Component\Form\Extension\DataCollector\Type\DataCollectorTypeExtension
If you pass both a form type and an option name, the command displays the full definition of the given option:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
$ ./bin/console debug:form 'App\Form\PostType' label_attr
App\Form\PostType (label_attr)
==============================
---------------- -----------
Required false
---------------- -----------
Default []
---------------- -----------
Allowed types ["array"]
---------------- -----------
Allowed values -
---------------- -----------
Normalizer -
---------------- -----------
Lastly, all this debug information is also available in JSON format just by adding
the --format=json
option when executing the command.
Help the Symfony project!
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.
Thanks to @roONL as active reviewer of each PR.