Skip to content

Commit 82afb31

Browse files
committed
Updated form/* articles to Symfony 4
1 parent 4d5ebc4 commit 82afb31

10 files changed

+34
-32
lines changed

form/action_method.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ form, you can use ``setAction()`` and ``setMethod()``:
2525
2626
class DefaultController extends Controller
2727
{
28-
public function newAction()
28+
public function new()
2929
{
3030
$form = $this->createFormBuilder($task)
3131
->setAction($this->generateUrl('target_route'))
@@ -83,7 +83,7 @@ options:
8383
8484
class DefaultController extends Controller
8585
{
86-
public function newAction()
86+
public function new()
8787
{
8888
// ...
8989

form/create_form_type_extension.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ your class as a service and using the ``form.type_extension`` tag:
7171

7272
.. code-block:: yaml
7373
74+
# config/services.yaml
7475
services:
7576
# ...
7677
@@ -80,6 +81,7 @@ your class as a service and using the ``form.type_extension`` tag:
8081
8182
.. code-block:: xml
8283
84+
<!-- config/services.xml -->
8385
<?xml version="1.0" encoding="UTF-8" ?>
8486
<container xmlns="http://symfony.com/schema/dic/services"
8587
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -95,6 +97,7 @@ your class as a service and using the ``form.type_extension`` tag:
9597
9698
.. code-block:: php
9799
100+
// config/services.php
98101
use App\Form\Extension\ImageTypeExtension;
99102
use Symfony\Component\Form\Extension\Core\Type\FileType;
100103
@@ -217,7 +220,7 @@ Specifically, you need to override the ``file_widget`` block:
217220

218221
.. code-block:: html+twig
219222

220-
{# app/Resources/fields.html.twig #}
223+
{# templates/form/fields.html.twig #}
221224
{% extends 'form_div_layout.html.twig' %}
222225

223226
{% block file_widget %}
@@ -233,7 +236,7 @@ Specifically, you need to override the ``file_widget`` block:
233236

234237
.. code-block:: html+php
235238

236-
<!-- app/Resources/file_widget.html.php -->
239+
<!-- templates/form/file_widget.html.php -->
237240
<?php echo $view['form']->widget($form) ?>
238241
<?php if (null !== $image_url): ?>
239242
<img src="<?php echo $view['assets']->getUrl($image_url) ?>"/>

form/direct_submit.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ submissions::
1010
use Symfony\Component\HttpFoundation\Request;
1111
// ...
1212

13-
public function newAction(Request $request)
13+
public function new(Request $request)
1414
{
1515
$form = $this->createFormBuilder()
1616
// ...
@@ -47,7 +47,7 @@ method, pass the submitted data directly to
4747
use Symfony\Component\HttpFoundation\Request;
4848
// ...
4949

50-
public function newAction(Request $request)
50+
public function new(Request $request)
5151
{
5252
$form = $this->createFormBuilder()
5353
// ...

form/dynamic_form_modification.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ In a controller, create the form like normal::
344344

345345
class FriendMessageController extends Controller
346346
{
347-
public function newAction(Request $request)
347+
public function new(Request $request)
348348
{
349349
$form = $this->createForm(FriendMessageFormType::class);
350350

@@ -392,7 +392,7 @@ sport like this::
392392
{
393393
$builder
394394
->add('sport', EntityType::class, array(
395-
'class' => 'App:Sport',
395+
'class' => 'App\Entity\Sport',
396396
'placeholder' => '',
397397
))
398398
;
@@ -409,7 +409,7 @@ sport like this::
409409
$positions = null === $sport ? array() : $sport->getAvailablePositions();
410410

411411
$form->add('position', EntityType::class, array(
412-
'class' => 'App:Position',
412+
'class' => 'App\Entity\Position',
413413
'placeholder' => '',
414414
'choices' => $positions,
415415
));
@@ -456,7 +456,7 @@ The type would now look like::
456456
{
457457
$builder
458458
->add('sport', EntityType::class, array(
459-
'class' => 'App:Sport',
459+
'class' => 'App\Entity\Sport',
460460
'placeholder' => '',
461461
));
462462
;
@@ -465,7 +465,7 @@ The type would now look like::
465465
$positions = null === $sport ? array() : $sport->getAvailablePositions();
466466

467467
$form->add('position', EntityType::class, array(
468-
'class' => 'App:Position',
468+
'class' => 'App\Entity\Position',
469469
'placeholder' => '',
470470
'choices' => $positions,
471471
));
@@ -518,7 +518,7 @@ your application. Assume that you have a sport meetup creation controller::
518518

519519
class MeetupController extends Controller
520520
{
521-
public function createAction(Request $request)
521+
public function create(Request $request)
522522
{
523523
$meetup = new SportMeetup();
524524
$form = $this->createForm(SportMeetupType::class, $meetup);
@@ -578,7 +578,7 @@ field according to the current selection in the ``sport`` field:
578578

579579
.. code-block:: html+php
580580

581-
<!-- templates/Meetup/create.html.php -->
581+
<!-- templates/meetup/create.html.php -->
582582
<?php echo $view['form']->start($form) ?>
583583
<?php echo $view['form']->row($form['sport']) ?> <!-- <select id="meetup_sport" ... -->
584584
<?php echo $view['form']->row($form['position']) ?> <!-- <select id="meetup_position" ... -->

form/form_collections.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ In your controller, you'll create a new form from the ``TaskType``::
156156

157157
class TaskController extends Controller
158158
{
159-
public function newAction(Request $request)
159+
public function new(Request $request)
160160
{
161161
$task = new Task();
162162

@@ -215,7 +215,7 @@ zero tags when first created).
215215

216216
.. code-block:: html+php
217217

218-
<!-- src/Resources/views/Task/new.html.php -->
218+
<!-- templates/task/new.html.php -->
219219

220220
<!-- ... -->
221221

@@ -399,7 +399,7 @@ one example:
399399
// Replace '__name__label__' in the prototype's HTML to
400400
// instead be a number based on how many items we have
401401
// newForm = newForm.replace(/__name__label__/g, index);
402-
402+
403403
// Replace '__name__' in the prototype's HTML to
404404
// instead be a number based on how many items we have
405405
newForm = newForm.replace(/__name__/g, index);
@@ -510,7 +510,7 @@ you will learn about next!).
510510
511511
.. code-block:: yaml
512512
513-
# src/Resources/config/doctrine/Task.orm.yml
513+
# src/Resources/config/doctrine/Task.orm.yaml
514514
App\Entity\Task:
515515
type: entity
516516
# ...
@@ -681,7 +681,7 @@ the relationship between the removed ``Tag`` and ``Task`` object.
681681
you'll need to do more work for the removed tags to persist correctly.
682682

683683
In this case, you can modify the controller to remove the relationship
684-
on the removed tag. This assumes that you have some ``editAction()`` which
684+
on the removed tag. This assumes that you have some ``edit()`` action which
685685
is handling the "update" of your Task::
686686

687687
// src/Controller/TaskController.php
@@ -690,7 +690,7 @@ the relationship between the removed ``Tag`` and ``Task`` object.
690690
use Doctrine\Common\Collections\ArrayCollection;
691691

692692
// ...
693-
public function editAction($id, Request $request)
693+
public function edit($id, Request $request)
694694
{
695695
$em = $this->getDoctrine()->getManager();
696696
$task = $em->getRepository(Task::class)->find($id);

form/form_customization.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ You can do this by including the ``only`` keyword after the list form themes:
366366

367367
.. code-block:: html+twig
368368

369-
{# app/Resources/views/common.html.twig #}
369+
{# templates/form/common.html.twig #}
370370
{% use "form_div_layout.html.twig" %}
371371

372372
{# ... #}
@@ -433,7 +433,7 @@ method:
433433

434434
The ``:form`` syntax is based on the functional names for templates:
435435
``Bundle:Directory``. As the form directory lives in the
436-
``app/Resources/views`` directory, the ``Bundle`` part is empty, resulting
436+
``templates/`` directory, the ``Bundle`` part is empty, resulting
437437
in ``:form``.
438438

439439
Referencing base Form Blocks (Twig specific)

form/form_dependencies.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ create your form::
3434
use App\Form\TaskType;
3535

3636
// ...
37-
public function newAction()
37+
public function new()
3838
{
3939
$em = $this->getDoctrine()->getManager();
4040

form/use_empty_data.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ How to Configure empty Data for a Form Class
77
The ``empty_data`` option allows you to specify an empty data set for your
88
form class. This empty data set would be used if you submit your form, but
99
haven't called ``setData()`` on your form or passed in data when you created
10-
your form. For example::
10+
your form. For example, in a controller::
1111

12-
public function indexAction()
12+
public function index()
1313
{
1414
$blog = ...;
1515

form/without_class.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ an array of the submitted data. This is actually really easy::
1515
use Symfony\Component\HttpFoundation\Request;
1616
// ...
1717

18-
public function contactAction(Request $request)
18+
public function contact(Request $request)
1919
{
2020
$defaultData = array('message' => 'Type your message here');
2121
$form = $this->createFormBuilder($defaultData)
@@ -102,7 +102,7 @@ but here's a short example:
102102
If you are using validation groups, you need to either reference the
103103
``Default`` group when creating the form, or set the correct group on
104104
the constraint you are adding.
105-
105+
106106
.. code-block:: php
107107
108108
new NotBlank(array('groups' => array('create', 'update')));

forms.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ from inside a controller::
8686

8787
class DefaultController extends Controller
8888
{
89-
public function newAction(Request $request)
89+
public function new(Request $request)
9090
{
9191
// create a task and give it some dummy data for this example
9292
$task = new Task();
@@ -221,7 +221,7 @@ your controller::
221221
// ...
222222
use Symfony\Component\HttpFoundation\Request;
223223

224-
public function newAction(Request $request)
224+
public function new(Request $request)
225225
{
226226
// just setup a fresh $task object (remove the dummy data)
227227
$task = new Task();
@@ -338,7 +338,7 @@ object.
338338
339339
.. code-block:: yaml
340340
341-
# src/Resources/config/validation.yml
341+
# src/Resources/config/validation.yaml
342342
App\Entity\Task:
343343
properties:
344344
task:
@@ -516,7 +516,7 @@ the type of your field and set it up for you. In this example, Symfony can
516516
guess from the validation rules that both the ``task`` field is a normal
517517
``TextType`` field and the ``dueDate`` field is a ``DateType`` field::
518518

519-
public function newAction()
519+
public function new()
520520
{
521521
$task = new Task();
522522

@@ -615,7 +615,7 @@ be used to quickly build a form object in the controller::
615615
// src/Controller/DefaultController.php
616616
use App\Form\TaskType;
617617

618-
public function newAction()
618+
public function new()
619619
{
620620
$task = ...;
621621
$form = $this->createForm(TaskType::class, $task);
@@ -708,4 +708,3 @@ Learn more
708708

709709
.. _`Symfony Form component`: https://github.com/symfony/form
710710
.. _`DateTime`: http://php.net/manual/en/class.datetime.php
711-
.. _`2.8 UPGRADE Log`: https://github.com/symfony/symfony/blob/2.8/UPGRADE-2.8.md#form

0 commit comments

Comments
 (0)