Open soullivaneuh opened 8 years ago
I found another way. I put all here so you can add it on documentation if you want to.
Create a CollectionTypeExtension
class:
<?php
namespace AppBundle\Form\Extension;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
/**
* @author Sullivan Senechal <soullivaneuh@gmail.com>
*/
final class CollectionTypeExtension extends AbstractTypeExtension
{
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
// Here we add the collection-type class
$view->vars['attr']['class'] = array_key_exists('class', $view->vars['attr'])
? $view->vars['attr']['class'].' collection-type'
: 'collection-type';
}
/**
* {@inheritdoc}
*/
public function getExtendedType()
{
return CollectionType::class;
}
}
And enable the service:
form.extension.collection:
class: AppBundle\Form\Extension\CollectionTypeExtension
tags:
- { name: form.type_extension, extended_type: Symfony\Component\Form\Extension\Core\Type\CollectionType }
That's all! :+1:
According to your twig doc header:
So I did from config:
And in
form_generic_fields.html.twig
, I want to always addcollection-type
class like this:The problem is this as no effect at all because your template also override this block and don't have any parent.
Is that a solvable issue or should I do it with another way?