Skip to content

Instantly share code, notes, and snippets.

@jumika
Forked from Venzon/gist:8694089
Last active August 29, 2015 14:01
Show Gist options
  • Save jumika/e2f0a5b3d4faf277307a to your computer and use it in GitHub Desktop.
Save jumika/e2f0a5b3d4faf277307a to your computer and use it in GitHub Desktop.
<?php
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Form\FormBuilderInterface;
class CollectionPrototypeDataTypeExtension extends AbstractTypeExtension {
public function buildForm(FormBuilderInterface $builder, array $options) {
parent::buildForm($builder, $options);
if(($prototypeFormBuilder = $builder->getAttribute('prototype')) && isset($options['prototype_data'])) {
$prototypeFormBuilder->setData($options['prototype_data']);
}
}
public function setDefaultOptions(OptionsResolverInterface $resolver) {
$resolver->setOptional(array('prototype_data'));
}
public function getExtendedType() {
return 'collection';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment