Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9458a09

Browse files
committed
feature#5834 Updated form aliases to FQCNs for forms in book and component (hiddewie)
This PR was merged into the 2.8 branch.Discussion----------Updated form aliases to FQCNs for forms in book and component| Q | A|------------- | ---| Doc fix? | yes| New docs? | no| Applies to | 2.8+| Fixed tickets |#5588For the 3.0 branch, all FQCNs should be updated to use the `::class` constant.Commits-------e103627 Fixed wrong indendationf8b080d Found more places which use old form types3237a34 Updated form constant usage3ab3830 Fixed PHP 5.5+ reference in form component291a42a Fixed removed XML tag in form book0820e69 Updated form aliases to FQCNs for forms in book and component
2 parents329182d +e103627 commit9458a09

File tree

13 files changed

+349
-229
lines changed

13 files changed

+349
-229
lines changed

‎best_practices/forms.rst

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,20 @@ form in its own PHP class::
2222
use Symfony\Component\Form\AbstractType;
2323
use Symfony\Component\Form\FormBuilderInterface;
2424
use Symfony\Component\OptionsResolver\OptionsResolver;
25+
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
26+
use Symfony\Component\Form\Extension\Core\Type\EmailType;
27+
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
2528

2629
class PostType extends AbstractType
2730
{
2831
public function buildForm(FormBuilderInterface $builder, array $options)
2932
{
3033
$builder
3134
->add('title')
32-
->add('summary','textarea')
33-
->add('content','textarea')
34-
->add('authorEmail','email')
35-
->add('publishedAt','datetime')
35+
->add('summary',TextareaType::class)
36+
->add('content',TextareaType::class)
37+
->add('authorEmail',EmailType::class)
38+
->add('publishedAt',DateTimeType::class)
3639
;
3740
}
3841

@@ -42,22 +45,17 @@ form in its own PHP class::
4245
'data_class' => 'AppBundle\Entity\Post'
4346
));
4447
}
45-
46-
public function getName()
47-
{
48-
return 'post';
49-
}
5048
}
5149

52-
To use the class, use ``createForm`` andinstantiate thenewclass::
50+
To use the class, use ``createForm`` andpass thefully qualifiedclass name::
5351

5452
use AppBundle\Form\PostType;
5553
// ...
5654

5755
public function newAction(Request $request)
5856
{
5957
$post = new Post();
60-
$form = $this->createForm(newPostType(), $post);
58+
$form = $this->createForm(PostType::class, $post);
6159

6260
// ...
6361
}
@@ -97,7 +95,7 @@ directly in your form class, this would effectively limit the scope of that form
9795
{
9896
$builder
9997
// ...
100-
->add('save','submit', array('label' => 'Create Post'))
98+
->add('save',SubmitType::class, array('label' => 'Create Post'))
10199
;
102100
}
103101
@@ -122,7 +120,7 @@ some developers configure form buttons in the controller::
122120
public function newAction(Request $request)
123121
{
124122
$post = new Post();
125-
$form = $this->createForm(newPostType(), $post);
123+
$form = $this->createForm(PostType::class, $post);
126124
$form->add('submit', 'submit', array(
127125
'label' => 'Create',
128126
'attr' => array('class' => 'btn btn-default pull-right')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp