EditPostForm::buildForm()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 9.44
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Explicit Architecture POC,
7
 * which is created on top of the Symfony Demo application.
8
 *
9
 * (c) Herberto Graça <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace Acme\App\Presentation\Web\Infrastructure\Form\Symfony\Form;
16
17
use Acme\App\Core\Component\Blog\Domain\Post\Post;
18
use Acme\App\Presentation\Web\Infrastructure\Form\Symfony\Type\DateTimePickerType;
19
use Acme\App\Presentation\Web\Infrastructure\Form\Symfony\Type\TagsInputType\TagsInputType;
20
use Symfony\Component\Form\AbstractType;
21
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
22
use Symfony\Component\Form\FormBuilderInterface;
23
use Symfony\Component\OptionsResolver\OptionsResolver;
24
25
/**
26
 * Defines the form used to edit blog posts.
27
 *
28
 * @author Ryan Weaver <[email protected]>
29
 * @author Javier Eguiluz <[email protected]>
30
 * @author Yonel Ceruto <[email protected]>
31
 * @author Herberto Graca <[email protected]>
32
 */
33
class EditPostForm extends AbstractType
34
{
35
    public function buildForm(FormBuilderInterface $builder, array $options): void
36
    {
37
        // For the full reference of options defined by each form field type
38
        // see https://symfony.com/doc/current/reference/forms/types.html
39
40
        // By default, form fields include the 'required' attribute, which enables
41
        // the client-side form validation. This means that you can't test the
42
        // server-side validation errors from the browser. To temporarily disable
43
        // this validation, set the 'required' attribute to 'false':
44
        // $builder->add('title', null, ['required' => false, ...]);
45
46
        $builder->add('title', null, [
47
                'attr' => ['autofocus' => true],
48
                'label' => 'label.title',
49
            ])
50
            ->add('summary', TextareaType::class, [
51
                'label' => 'label.summary',
52
            ])
53
            ->add('content', null, [
54
                'attr' => ['rows' => 20],
55
                'label' => 'label.content',
56
            ])
57
            ->add('publishedAt', DateTimePickerType::class, [
58
                'label' => 'label.published_at',
59
            ])
60
            ->add('tags', TagsInputType::class, [
61
                'label' => 'label.tags',
62
                'required' => false,
63
            ]);
64
    }
65
66
    public function configureOptions(OptionsResolver $resolver): void
67
    {
68
        $resolver->setDefaults([
69
            'data_class' => Post::class,
70
        ]);
71
    }
72
}
73