Skip to content

Fix #250: Replace form type object with classname string #253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions app/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ services:
tags:
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }

app.form.type.datetimepicker:
class: AppBundle\Form\Type\DateTimePickerType
tags:
- { name: form.type, alias: app_datetimepicker }

# Uncomment the following lines to define a service for the Post Doctrine repository.
# It's not mandatory to create these services, but if you use repositories a lot,
# these services simplify your code:
Expand Down
6 changes: 3 additions & 3 deletions src/AppBundle/Controller/Admin/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public function newAction(Request $request)
$post->setAuthorEmail($this->getUser()->getEmail());

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

$form->handleRequest($request);

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

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

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

$editForm->handleRequest($request);
Expand Down
4 changes: 2 additions & 2 deletions src/AppBundle/Controller/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function postShowAction(Post $post)
*/
public function commentNewAction(Request $request, Post $post)
{
$form = $this->createForm(new CommentType());
$form = $this->createForm('AppBundle\Form\CommentType');

$form->handleRequest($request);

Expand Down Expand Up @@ -111,7 +111,7 @@ public function commentNewAction(Request $request, Post $post)
*/
public function commentFormAction(Post $post)
{
$form = $this->createForm(new CommentType());
$form = $this->createForm('AppBundle\Form\CommentType');

return $this->render('blog/_comment_form.html.twig', array(
'post' => $post,
Expand Down
10 changes: 0 additions & 10 deletions src/AppBundle/Form/CommentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,4 @@ public function configureOptions(OptionsResolver $resolver)
'data_class' => 'AppBundle\Entity\Comment',
));
}

/**
* {@inheritdoc}
*/
public function getName()
{
// Best Practice: use 'app_' as the prefix of your custom form types names
// see http://symfony.com/doc/current/best_practices/forms.html#custom-form-field-types
return 'app_comment';
}
}
18 changes: 4 additions & 14 deletions src/AppBundle/Form/PostType.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'attr' => array('autofocus' => true),
'label' => 'label.title',
))
->add('summary', 'textarea', array('label' => 'label.summary'))
->add('content', 'textarea', array(
->add('summary', 'Symfony\Component\Form\Extension\Core\Type\TextareaType', array('label' => 'label.summary'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This summary field is a string type, why use textarea? or perhaps we should redefine it as text?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it doesn't necessary to change it to text... Even with 255 length more convenient work with textarea.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bocharsky-bw then, when users to type a text with 256 characters or more will be truncated and this could be an unexpected result for the user. I suggest then use maxlength 255 for this widget.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

max_length is deprecated option

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@voronkovich I meant to the html attribute:

'attr' => array('maxlength' => 255)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yceruto, ok.

->add('content', null, array(
'attr' => array('rows' => 20),
'label' => 'label.content',
))
->add('authorEmail', 'email', array('label' => 'label.author_email'))
->add('publishedAt', 'app_datetimepicker', array(
->add('authorEmail', null, array('label' => 'label.author_email'))
->add('publishedAt', 'AppBundle\Form\Type\DateTimePickerType', array(
'label' => 'label.published_at',
))
;
Expand All @@ -64,14 +64,4 @@ public function configureOptions(OptionsResolver $resolver)
'data_class' => 'AppBundle\Entity\Post',
));
}

/**
* {@inheritdoc}
*/
public function getName()
{
// Best Practice: use 'app_' as the prefix of your custom form types names
// see http://symfony.com/doc/current/best_practices/forms.html#custom-form-field-types
return 'app_post';
}
}
10 changes: 1 addition & 9 deletions src/AppBundle/Form/Type/DateTimePickerType.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,6 @@ public function configureOptions(OptionsResolver $resolver)
*/
public function getParent()
{
return 'datetime';
}

/**
* {@inheritdoc}
*/
public function getName()
{
return 'app_datetimepicker';
return 'Symfony\Component\Form\Extension\Core\Type\DateTimeType';
}
}