From f6a07216a22b370455290d74692f4d06b857449f Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Mon, 30 Mar 2020 14:33:29 +0200 Subject: [PATCH 1/3] Simplifying the code block --- form/form_collections.rst | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/form/form_collections.rst b/form/form_collections.rst index 00e524607fc..dc5bb404f45 100644 --- a/form/form_collections.rst +++ b/form/form_collections.rst @@ -255,13 +255,9 @@ add the ``allow_add`` option to your collection field:: // src/Form/TaskType.php - // ... - use Symfony\Component\Form\FormBuilderInterface; - public function buildForm(FormBuilderInterface $builder, array $options) { - $builder->add('description'); - + // ... $builder->add('tags', CollectionType::class, [ 'entry_type' => TagType::class, 'entry_options' => ['label' => false], From d3357508df8ca3471b245fa900af3f36553140a7 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Mon, 30 Mar 2020 14:40:37 +0200 Subject: [PATCH 2/3] Update form_collections.rst Fixing https://github.com/symfony/symfony-docs/pull/13446/checks --- form/form_collections.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/form/form_collections.rst b/form/form_collections.rst index dc5bb404f45..8f01b99911d 100644 --- a/form/form_collections.rst +++ b/form/form_collections.rst @@ -254,7 +254,7 @@ type expects to receive exactly two, otherwise an error will be thrown: add the ``allow_add`` option to your collection field:: // src/Form/TaskType.php - + public function buildForm(FormBuilderInterface $builder, array $options) { // ... From 4651356cecd4a53e9b423c121b91ae6abcc29fb0 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Mon, 30 Mar 2020 14:47:43 +0200 Subject: [PATCH 3/3] Update form_collections.rst Second attempt to fix https://github.com/symfony/symfony-docs/pull/13446/checks Fencing the code block in backticks --- form/form_collections.rst | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/form/form_collections.rst b/form/form_collections.rst index 8f01b99911d..257b3605de7 100644 --- a/form/form_collections.rst +++ b/form/form_collections.rst @@ -251,19 +251,21 @@ The first thing you need to do is to let the form collection know that it will receive an unknown number of tags. So far you've added two tags and the form type expects to receive exactly two, otherwise an error will be thrown: ``This form should not contain extra fields``. To make this flexible, -add the ``allow_add`` option to your collection field:: +add the ``allow_add`` option to your collection field: - // src/Form/TaskType.php - - public function buildForm(FormBuilderInterface $builder, array $options) - { - // ... - $builder->add('tags', CollectionType::class, [ - 'entry_type' => TagType::class, - 'entry_options' => ['label' => false], - 'allow_add' => true, - ]); - } +```php +// src/Form/TaskType.php + +public function buildForm(FormBuilderInterface $builder, array $options) +{ + // ... + $builder->add('tags', CollectionType::class, [ + 'entry_type' => TagType::class, + 'entry_options' => ['label' => false], + 'allow_add' => true, + ]); +} +``` In addition to telling the field to accept any number of submitted objects, the ``allow_add`` also makes a *"prototype"* variable available to you. This "prototype"