phiamo/MopaBootstrapBundle — pull request #952 by molchanoviv (2014-10-10 11:20:18+00:00)
Title: Fix for incorrect prototype placeholders replace in nested collections

Hello I faced to the issue with nested collections.
I have three form types.
First one. ProductType:

```php
add('name', 'text')
->add('productOptions', 'collection', [
'type' => 'product_option',
'options' => ['label_render' => false],
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'widget_add_btn' => [
'icon' => 'plus-sign',
'label' => 'Add product option'
],
'widget_remove_btn' => [
'icon' => 'minus-sign',
'label' => 'Remove'
]
])
;
}

/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Opensoft\Onp\Bundle\CoreBundle\Entity\Product',
'csrf_protection' => false,
));
}

/**
* @return string
*/
public function getName()
{
return 'product';
}
}
```

Second one. ProductOptionType:

```php
/**
* @Service("opensoft_onp_web.utils.main_menu_editor.product_option.form.type")
* @Tag("form.type", attributes = {"alias" = "product_option"})
*/
class ProductOptionType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add(
'productOptionValues',
'collection',
[
'type' => 'product_option_value',
'options' => ['label_render' => false],
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'widget_add_btn' => [
'icon' => 'plus-sign',
'label' => 'Add product option value'
],
'widget_remove_btn' => [
'icon' => 'minus-sign',
'label' => 'Remove'
]
]
);
}

/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(
array(
'data_class' => 'Opensoft\Onp\Bundle\CoreBundle\Entity\ProductOption',
'csrf_protection' => false,
)
);
}

/**
* @return string
*/
public function getName()
{
return 'product_option';
}
}
```

And the third one. ProductOptionValueType:

```php
/**
* Opensoft\Onp\Bundle\WebBundle\Form\Type\ProductOptionValueType
*
* @Service("opensoft_onp_web.utils.main_menu_editor.product_option_value.form.type")
* @Tag("form.type", attributes = {"alias" = "product_option_value"})
*
* @author Richard Fullmer
*/
class ProductOptionValueType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add(
'optionValue',
'entity',
[
'class' => 'Opensoft\\Onp\\Bundle\\CoreBundle\\Entity\\OptionValue',
'property' => 'title',
'label_attr' => array('class' => 'col-lg-2'),
'attr' => array('class' => 'col-lg-10'),
]
)
->add('pricing', 'product_option_pricing')
->add(
'enabled',
'checkbox',
[
'required' => false,
'render_optional_text' => false,
]
)
->add(
'default',
'checkbox',
[
'required' => false,
'render_optional_text' => false,
]
);
}

/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(
array(
'data_class' => 'Opensoft\Onp\Bundle\CoreBundle\Entity\ProductOptionValue',
)
);
}

/**
* @return string
*/
public function getName()
{
return 'product_option_value';
}
}
```

So when i try to add ProductOption and than ProductOptionValue and save it only ProductOption is saved. It happened because function addPrototype replaced placeholders of ProductOption and ProductOptionValue. After my fix it replaces only a first one.