Skip to content

Commit d5f4b11

Browse files
committed
feature #253 Fix #250: Replace form type object with classname string (bocharsky-bw)
This PR was squashed before being merged into the master branch (closes #253). Discussion ---------- Fix #250: Replace form type object with classname string Commits ------- 25e49b1 Fix #250: Replace form type object with classname string
2 parents be15427 + 25e49b1 commit d5f4b11

File tree

6 files changed

+10
-43
lines changed

6 files changed

+10
-43
lines changed

app/config/services.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ services:
2828
tags:
2929
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
3030

31-
app.form.type.datetimepicker:
32-
class: AppBundle\Form\Type\DateTimePickerType
33-
tags:
34-
- { name: form.type, alias: app_datetimepicker }
35-
3631
# Uncomment the following lines to define a service for the Post Doctrine repository.
3732
# It's not mandatory to create these services, but if you use repositories a lot,
3833
# these services simplify your code:

src/AppBundle/Controller/Admin/BlogController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public function newAction(Request $request)
7474
$post->setAuthorEmail($this->getUser()->getEmail());
7575

7676
// See http://symfony.com/doc/current/book/forms.html#submitting-forms-with-multiple-buttons
77-
$form = $this->createForm(new PostType(), $post)
78-
->add('saveAndCreateNew', 'submit');
77+
$form = $this->createForm('AppBundle\Form\PostType', $post)
78+
->add('saveAndCreateNew', 'Symfony\Component\Form\Extension\Core\Type\SubmitType');
7979

8080
$form->handleRequest($request);
8181

@@ -146,7 +146,7 @@ public function editAction(Post $post, Request $request)
146146

147147
$entityManager = $this->getDoctrine()->getManager();
148148

149-
$editForm = $this->createForm(new PostType(), $post);
149+
$editForm = $this->createForm('AppBundle\Form\PostType', $post);
150150
$deleteForm = $this->createDeleteForm($post);
151151

152152
$editForm->handleRequest($request);

src/AppBundle/Controller/BlogController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function postShowAction(Post $post)
7373
*/
7474
public function commentNewAction(Request $request, Post $post)
7575
{
76-
$form = $this->createForm(new CommentType());
76+
$form = $this->createForm('AppBundle\Form\CommentType');
7777

7878
$form->handleRequest($request);
7979

@@ -110,7 +110,7 @@ public function commentNewAction(Request $request, Post $post)
110110
*/
111111
public function commentFormAction(Post $post)
112112
{
113-
$form = $this->createForm(new CommentType());
113+
$form = $this->createForm('AppBundle\Form\CommentType');
114114

115115
return $this->render('blog/_comment_form.html.twig', array(
116116
'post' => $post,

src/AppBundle/Form/CommentType.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,4 @@ public function configureOptions(OptionsResolver $resolver)
5252
'data_class' => 'AppBundle\Entity\Comment',
5353
));
5454
}
55-
56-
/**
57-
* {@inheritdoc}
58-
*/
59-
public function getName()
60-
{
61-
// Best Practice: use 'app_' as the prefix of your custom form types names
62-
// see http://symfony.com/doc/current/best_practices/forms.html#custom-form-field-types
63-
return 'app_comment';
64-
}
6555
}

src/AppBundle/Form/PostType.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ public function buildForm(FormBuilderInterface $builder, array $options)
4343
'attr' => array('autofocus' => true),
4444
'label' => 'label.title',
4545
))
46-
->add('summary', 'textarea', array('label' => 'label.summary'))
47-
->add('content', 'textarea', array(
46+
->add('summary', 'Symfony\Component\Form\Extension\Core\Type\TextareaType', array('label' => 'label.summary'))
47+
->add('content', null, array(
4848
'attr' => array('rows' => 20),
4949
'label' => 'label.content',
5050
))
51-
->add('authorEmail', 'email', array('label' => 'label.author_email'))
52-
->add('publishedAt', 'app_datetimepicker', array(
51+
->add('authorEmail', null, array('label' => 'label.author_email'))
52+
->add('publishedAt', 'AppBundle\Form\Type\DateTimePickerType', array(
5353
'label' => 'label.published_at',
5454
))
5555
;
@@ -64,14 +64,4 @@ public function configureOptions(OptionsResolver $resolver)
6464
'data_class' => 'AppBundle\Entity\Post',
6565
));
6666
}
67-
68-
/**
69-
* {@inheritdoc}
70-
*/
71-
public function getName()
72-
{
73-
// Best Practice: use 'app_' as the prefix of your custom form types names
74-
// see http://symfony.com/doc/current/best_practices/forms.html#custom-form-field-types
75-
return 'app_post';
76-
}
7767
}

src/AppBundle/Form/Type/DateTimePickerType.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,6 @@ public function configureOptions(OptionsResolver $resolver)
6060
*/
6161
public function getParent()
6262
{
63-
return 'datetime';
64-
}
65-
66-
/**
67-
* {@inheritdoc}
68-
*/
69-
public function getName()
70-
{
71-
return 'app_datetimepicker';
63+
return 'Symfony\Component\Form\Extension\Core\Type\DateTimeType';
7264
}
7365
}

0 commit comments

Comments
 (0)