|
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\Comment\Comment; |
|
18
|
|
|
use Symfony\Component\Form\AbstractType; |
|
19
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
|
20
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Defines the form used to create and manipulate blog comments. Although in this |
|
24
|
|
|
* case the form is trivial and we could build it inside the controller, a good |
|
25
|
|
|
* practice is to always define your forms as classes. |
|
26
|
|
|
* |
|
27
|
|
|
* See https://symfony.com/doc/current/book/forms.html#creating-form-classes |
|
28
|
|
|
* |
|
29
|
|
|
* @author Ryan Weaver <[email protected]> |
|
30
|
|
|
* @author Javier Eguiluz <[email protected]> |
|
31
|
|
|
* @author Herberto Graca <[email protected]> |
|
32
|
|
|
*/ |
|
33
|
|
|
class CommentForm extends AbstractType |
|
34
|
|
|
{ |
|
35
|
|
|
/** |
|
36
|
|
|
* {@inheritdoc} |
|
37
|
|
|
*/ |
|
38
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options): void |
|
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('content', null, ['required' => false]); |
|
45
|
|
|
|
|
46
|
|
|
$builder->add('content'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritdoc} |
|
51
|
|
|
*/ |
|
52
|
|
|
public function configureOptions(OptionsResolver $resolver): void |
|
53
|
|
|
{ |
|
54
|
|
|
$resolver->setDefaults(['data_class' => Comment::class]); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|