]>
Commit | Line | Data |
---|---|---|
4f5b44bd NL |
1 | <?php |
2 | ||
3 | namespace Symfony\Component\Form\Tests\Fixtures; | |
4 | ||
5 | use Symfony\Component\Form\AbstractType; | |
6 | use Symfony\Component\Form\FormEvents; | |
7 | use Symfony\Component\Form\FormEvent; | |
8 | use Symfony\Component\Form\FormBuilderInterface; | |
9 | ||
10 | class AlternatingRowType extends AbstractType | |
11 | { | |
12 | public function buildForm(FormBuilderInterface $builder, array $options) | |
13 | { | |
14 | $formFactory = $builder->getFormFactory(); | |
15 | ||
16 | $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($formFactory) { | |
17 | $form = $event->getForm(); | |
18 | $type = $form->getName() % 2 === 0 ? 'text' : 'textarea'; | |
19 | $form->add('title', $type); | |
20 | }); | |
21 | } | |
22 | ||
23 | public function getName() | |
24 | { | |
25 | return 'alternating_row'; | |
26 | } | |
27 | } |