|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\UX\LiveComponent\Tests\Fixture\Component; |
| 13 | + |
| 14 | +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
| 15 | +use Symfony\Component\Form\Extension\Core\Type\CheckboxType; |
| 16 | +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
| 17 | +use Symfony\Component\Form\Extension\Core\Type\FileType; |
| 18 | +use Symfony\Component\Form\Extension\Core\Type\HiddenType; |
| 19 | +use Symfony\Component\Form\Extension\Core\Type\RangeType; |
| 20 | +use Symfony\Component\Form\Extension\Core\Type\TextareaType; |
| 21 | +use Symfony\Component\Form\Extension\Core\Type\TextType; |
| 22 | +use Symfony\Component\Form\FormBuilderInterface; |
| 23 | +use Symfony\Component\Form\FormInterface; |
| 24 | +use Symfony\UX\LiveComponent\Attribute\AsLiveComponent; |
| 25 | +use Symfony\UX\LiveComponent\ComponentWithFormTrait; |
| 26 | +use Symfony\UX\LiveComponent\DefaultActionTrait; |
| 27 | + |
| 28 | +/** |
| 29 | + * @author Jakub Caban <[email protected]> |
| 30 | + */ |
| 31 | +#[AsLiveComponent('component6')] |
| 32 | +class Component6 extends AbstractController |
| 33 | +{ |
| 34 | + use DefaultActionTrait; |
| 35 | + use ComponentWithFormTrait; |
| 36 | + |
| 37 | + private FormBuilderInterface $builder; |
| 38 | + |
| 39 | + public function __construct(FormBuilderInterface $builder) |
| 40 | + { |
| 41 | + $this->builder = $builder; |
| 42 | + } |
| 43 | + |
| 44 | + protected function instantiateForm(): FormInterface |
| 45 | + { |
| 46 | + $this->builder |
| 47 | + ->add('text', TextType::class) |
| 48 | + ->add('textarea', TextareaType::class) |
| 49 | + ->add('range', RangeType::class) |
| 50 | + ->add('choice', ChoiceType::class, [ |
| 51 | + 'choices' => [ |
| 52 | + 'foo' => 1, |
| 53 | + 'bar' => 2 |
| 54 | + ] |
| 55 | + ]) |
| 56 | + ->add('choice_expanded', ChoiceType::class, [ |
| 57 | + 'choices' => [ |
| 58 | + 'foo' => 1, |
| 59 | + 'bar' => 2 |
| 60 | + ], |
| 61 | + 'expanded' => true |
| 62 | + ]) |
| 63 | + ->add('checkbox', CheckboxType::class) |
| 64 | + ->add('file', FileType::class) |
| 65 | + ->add('hidden', HiddenType::class) |
| 66 | + ; |
| 67 | + |
| 68 | + return $this->builder->getForm(); |
| 69 | + } |
| 70 | +} |
0 commit comments