Skip to content

Commit

Permalink
feature #5834 Updated form aliases to FQCNs for forms in book and com…
Browse files Browse the repository at this point in the history
…ponent (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 | #5588

For the 3.0 branch, all FQCNs should be updated to use the `::class` constant.

Commits
-------

e103627 Fixed wrong indendation
f8b080d Found more places which use old form types
3237a34 Updated form constant usage
3ab3830 Fixed PHP 5.5+ reference in form component
291a42a Fixed removed XML tag in form book
0820e69 Updated form aliases to FQCNs for forms in book and component
  • Loading branch information
weaverryan committed Nov 27, 2015
2 parents 329182d + e103627 commit 9458a09
Show file tree
Hide file tree
Showing 13 changed files with 349 additions and 229 deletions.
24 changes: 11 additions & 13 deletions best_practices/forms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@ form in its own PHP class::
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;

class PostType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('title')
->add('summary', 'textarea')
->add('content', 'textarea')
->add('authorEmail', 'email')
->add('publishedAt', 'datetime')
->add('summary', TextareaType::class)
->add('content', TextareaType::class)
->add('authorEmail', EmailType::class)
->add('publishedAt', DateTimeType::class)
;
}

Expand All @@ -42,22 +45,17 @@ form in its own PHP class::
'data_class' => 'AppBundle\Entity\Post'
));
}

public function getName()
{
return 'post';
}
}

To use the class, use ``createForm`` and instantiate the new class::
To use the class, use ``createForm`` and pass the fully qualified class name::

use AppBundle\Form\PostType;
// ...

public function newAction(Request $request)
{
$post = new Post();
$form = $this->createForm(new PostType(), $post);
$form = $this->createForm(PostType::class, $post);

// ...
}
Expand Down Expand Up @@ -97,7 +95,7 @@ directly in your form class, this would effectively limit the scope of that form
{
$builder
// ...
->add('save', 'submit', array('label' => 'Create Post'))
->add('save', SubmitType::class, array('label' => 'Create Post'))
;
}
Expand All @@ -122,7 +120,7 @@ some developers configure form buttons in the controller::
public function newAction(Request $request)
{
$post = new Post();
$form = $this->createForm(new PostType(), $post);
$form = $this->createForm(PostType::class, $post);
$form->add('submit', 'submit', array(
'label' => 'Create',
'attr' => array('class' => 'btn btn-default pull-right')
Expand Down
Loading

0 comments on commit 9458a09

Please sign in to comment.