From fc7b84cdf08902ca6e8309b43a40b50a967203e1 Mon Sep 17 00:00:00 2001 From: Kristen Gilden Date: Fri, 24 Oct 2014 21:38:39 +0300 Subject: [PATCH 1/3] [#5095] Add "prototype_data" option to collection type --- .../Form/Extension/Core/Type/CollectionType.php | 8 +++++++- .../Tests/Extension/Core/Type/CollectionTypeTest.php | 12 ++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php b/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php index 2fed7cea88a4c..2805ef10e9909 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php @@ -55,7 +55,12 @@ public function buildView(FormView $view, FormInterface $form, array $options) )); if ($form->getConfig()->hasAttribute('prototype')) { - $view->vars['prototype'] = $form->getConfig()->getAttribute('prototype')->createView($view); + $view->vars['prototype'] = $form + ->getConfig() + ->getAttribute('prototype') + ->setData($options['prototype_data']) + ->createView($view) + ; } } @@ -84,6 +89,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) 'allow_add' => false, 'allow_delete' => false, 'prototype' => true, + 'prototype_data' => null, 'prototype_name' => '__name__', 'type' => 'text', 'options' => array(), diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php index 589ccdbb7ac21..a5b90579ab381 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php @@ -274,4 +274,16 @@ public function testPrototypeDefaultLabel() $this->assertSame('__test__label__', $form->createView()->vars['prototype']->vars['label']); } + + public function testPrototypeData() + { + $form = $this->factory->create('collection', array(), array( + 'type' => 'text', + 'allow_add' => true, + 'prototype' => true, + 'prototype_data' => 'foo', + )); + + $this->assertSame('foo', $form->createView()->vars['prototype']->vars['value']); + } } From f520c3c8fce881b5d5a7c71a80fd8268cd10df3b Mon Sep 17 00:00:00 2001 From: Kristen Gilden Date: Sat, 31 Jan 2015 23:33:36 +0200 Subject: [PATCH 2/3] [#5095] Make sure "prototype_data" overrides "data" option The "data" option under the "options" option intended for the target form type would previously overwrite "prototype_data". --- .../Form/Extension/Core/Type/CollectionType.php | 11 ++++------- .../Tests/Extension/Core/Type/CollectionTypeTest.php | 3 +++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php b/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php index 2805ef10e9909..817d67e2272bf 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php @@ -29,7 +29,9 @@ public function buildForm(FormBuilderInterface $builder, array $options) if ($options['allow_add'] && $options['prototype']) { $prototype = $builder->create($options['prototype_name'], $options['type'], array_replace(array( 'label' => $options['prototype_name'].'label__', - ), $options['options'])); + ), $options['options'], array( + 'data' => $options['prototype_data'], + ))); $builder->setAttribute('prototype', $prototype->getForm()); } @@ -55,12 +57,7 @@ public function buildView(FormView $view, FormInterface $form, array $options) )); if ($form->getConfig()->hasAttribute('prototype')) { - $view->vars['prototype'] = $form - ->getConfig() - ->getAttribute('prototype') - ->setData($options['prototype_data']) - ->createView($view) - ; + $view->vars['prototype'] = $form->getConfig()->getAttribute('prototype')->createView($view); } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php index a5b90579ab381..45aeed0abc3f6 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php @@ -282,6 +282,9 @@ public function testPrototypeData() 'allow_add' => true, 'prototype' => true, 'prototype_data' => 'foo', + 'options' => array( + 'data' => 'bar', + ), )); $this->assertSame('foo', $form->createView()->vars['prototype']->vars['value']); From cfec9de08d82153a34d082b118b51329969cd4b5 Mon Sep 17 00:00:00 2001 From: Kristen Gilden Date: Sat, 31 Jan 2015 23:36:27 +0200 Subject: [PATCH 3/3] [#5095] Improve prototype_data test formatting consistency --- .../Form/Tests/Extension/Core/Type/CollectionTypeTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php index 45aeed0abc3f6..ef00ea25bd84a 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php @@ -278,11 +278,11 @@ public function testPrototypeDefaultLabel() public function testPrototypeData() { $form = $this->factory->create('collection', array(), array( - 'type' => 'text', - 'allow_add' => true, - 'prototype' => true, + 'type' => 'text', + 'allow_add' => true, + 'prototype' => true, 'prototype_data' => 'foo', - 'options' => array( + 'options' => array( 'data' => 'bar', ), )); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy