Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save peterrehm/8842859 to your computer and use it in GitHub Desktop.
Save peterrehm/8842859 to your computer and use it in GitHub Desktop.
<?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';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment