Last active
August 29, 2015 13:55
-
-
Save Venzon/8694089 to your computer and use it in GitHub Desktop.
Symfony2 Collection Type with default value support by prototype_data option
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\FormBuilderInterface; | |
class CollectionPrototypeDataType extends AbstractType | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public function buildForm(FormBuilderInterface $builder, array $options) | |
{ | |
parent::buildForm($builder, $options); | |
if (null !== ($prototypeFormBuilder = $builder->getAttribute('prototype'))) { | |
/** @var $prototypeFormBuilder FormBuilderInterface */ | |
$prototypeFormBuilder->setData($options['prototype_data']); | |
} | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getName() | |
{ | |
return 'collection'; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getParent() | |
{ | |
return 'collection'; | |
} | |
} |
I think extending collection with a type with the name collection causes an infinite loop in 2.5.
I've forked this gist and converted it to a form type extension.
see: https://gist.github.com/jumika/e2f0a5b3d4faf277307a
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What does the service config look like for this form type?