Skip to content

Instantly share code, notes, and snippets.

@adrienbrault
Created January 29, 2013 17:43
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save adrienbrault/4666086 to your computer and use it in GitHub Desktop.
Save adrienbrault/4666086 to your computer and use it in GitHub Desktop.
Workaround to get the same feature as in https://github.com/symfony/symfony/pull/6910
<?php
namespace Incenteev\Bundle\Form\Extension;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
/**
* @author Adrien Brault <adrien.brault@gmail.com>
*/
class CollectionTypeExtension extends AbstractTypeExtension
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
if (null !== ($prototypeFormBuilder = $builder->getAttribute('prototype'))) {
/** @var $prototypeFormBuilder FormBuilderInterface */
$prototypeFormBuilder->setData($options['prototype_data']);
}
}
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'prototype_data' => null,
));
}
/**
* {@inheritdoc}
*/
public function getExtendedType()
{
return 'collection';
}
}
@Bendihossan
Copy link

Thanks so much for this :)

Copy link

ghost commented May 23, 2014

Thanks! Works perfectly!

@mimol91
Copy link

mimol91 commented Jun 24, 2014

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment