Skip to content

Updated form/* articles to Symfony 4 #8755

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

Merged
merged 2 commits into from
Nov 29, 2017
Merged
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
4 changes: 2 additions & 2 deletions form/action_method.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ form, you can use ``setAction()`` and ``setMethod()``:

class DefaultController extends Controller
{
public function newAction()
public function new()
{
$form = $this->createFormBuilder($task)
->setAction($this->generateUrl('target_route'))
Expand Down Expand Up @@ -83,7 +83,7 @@ options:

class DefaultController extends Controller
{
public function newAction()
public function new()
{
// ...

Expand Down
2 changes: 1 addition & 1 deletion form/create_custom_field_type.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ link for details), create a ``shipping_widget`` block to handle this:

.. code-block:: html+php

<!-- templates/form/shipping_widget.html.php -->
<!-- src/Resources/shipping_widget.html.php -->
<?php if ($expanded) : ?>
<ul <?php $view['form']->block($form, 'widget_container_attributes') ?>>
<?php foreach ($form as $child) : ?>
Expand Down
7 changes: 5 additions & 2 deletions form/create_form_type_extension.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ your class as a service and using the ``form.type_extension`` tag:

.. code-block:: yaml

# config/services.yaml
services:
# ...

Expand All @@ -80,6 +81,7 @@ your class as a service and using the ``form.type_extension`` tag:

.. code-block:: xml

<!-- config/services.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand All @@ -95,6 +97,7 @@ your class as a service and using the ``form.type_extension`` tag:

.. code-block:: php

// config/services.php
use App\Form\Extension\ImageTypeExtension;
use Symfony\Component\Form\Extension\Core\Type\FileType;

Expand Down Expand Up @@ -217,7 +220,7 @@ Specifically, you need to override the ``file_widget`` block:

.. code-block:: html+twig

{# app/Resources/fields.html.twig #}
{# templates/form/fields.html.twig #}
{% extends 'form_div_layout.html.twig' %}

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

.. code-block:: html+php

<!-- app/Resources/file_widget.html.php -->
<!-- src/Resources/file_widget.html.php -->
<?php echo $view['form']->widget($form) ?>
<?php if (null !== $image_url): ?>
<img src="<?php echo $view['assets']->getUrl($image_url) ?>"/>
Expand Down
4 changes: 2 additions & 2 deletions form/direct_submit.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ submissions::
use Symfony\Component\HttpFoundation\Request;
// ...

public function newAction(Request $request)
public function new(Request $request)
{
$form = $this->createFormBuilder()
// ...
Expand Down Expand Up @@ -47,7 +47,7 @@ method, pass the submitted data directly to
use Symfony\Component\HttpFoundation\Request;
// ...

public function newAction(Request $request)
public function new(Request $request)
{
$form = $this->createFormBuilder()
// ...
Expand Down
14 changes: 7 additions & 7 deletions form/dynamic_form_modification.rst
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ In a controller, create the form like normal::

class FriendMessageController extends Controller
{
public function newAction(Request $request)
public function new(Request $request)
{
$form = $this->createForm(FriendMessageFormType::class);

Expand Down Expand Up @@ -392,7 +392,7 @@ sport like this::
{
$builder
->add('sport', EntityType::class, array(
'class' => 'App:Sport',
'class' => 'App\Entity\Sport',
'placeholder' => '',
))
;
Expand All @@ -409,7 +409,7 @@ sport like this::
$positions = null === $sport ? array() : $sport->getAvailablePositions();

$form->add('position', EntityType::class, array(
'class' => 'App:Position',
'class' => 'App\Entity\Position',
'placeholder' => '',
'choices' => $positions,
));
Expand Down Expand Up @@ -456,7 +456,7 @@ The type would now look like::
{
$builder
->add('sport', EntityType::class, array(
'class' => 'App:Sport',
'class' => 'App\Entity\Sport',
'placeholder' => '',
));
;
Expand All @@ -465,7 +465,7 @@ The type would now look like::
$positions = null === $sport ? array() : $sport->getAvailablePositions();

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

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

.. code-block:: html+php

<!-- templates/Meetup/create.html.php -->
<!-- templates/meetup/create.html.php -->
<?php echo $view['form']->start($form) ?>
<?php echo $view['form']->row($form['sport']) ?> <!-- <select id="meetup_sport" ... -->
<?php echo $view['form']->row($form['position']) ?> <!-- <select id="meetup_position" ... -->
Expand Down
10 changes: 5 additions & 5 deletions form/form_collections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ In your controller, you'll create a new form from the ``TaskType``::

class TaskController extends Controller
{
public function newAction(Request $request)
public function new(Request $request)
{
$task = new Task();

Expand Down Expand Up @@ -215,7 +215,7 @@ zero tags when first created).

.. code-block:: html+php

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

<!-- ... -->

Expand Down Expand Up @@ -399,7 +399,7 @@ one example:
// Replace '__name__label__' in the prototype's HTML to
// instead be a number based on how many items we have
// newForm = newForm.replace(/__name__label__/g, index);

// Replace '__name__' in the prototype's HTML to
// instead be a number based on how many items we have
newForm = newForm.replace(/__name__/g, index);
Expand Down Expand Up @@ -681,7 +681,7 @@ the relationship between the removed ``Tag`` and ``Task`` object.
you'll need to do more work for the removed tags to persist correctly.

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

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

// ...
public function editAction($id, Request $request)
public function edit($id, Request $request)
{
$em = $this->getDoctrine()->getManager();
$task = $em->getRepository(Task::class)->find($id);
Expand Down
10 changes: 5 additions & 5 deletions form/form_customization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ You can do this by including the ``only`` keyword after the list form themes:

.. code-block:: html+twig

{# app/Resources/views/common.html.twig #}
{# templates/form/common.html.twig #}
{% use "form_div_layout.html.twig" %}

{# ... #}
Expand Down Expand Up @@ -401,7 +401,7 @@ file in order to customize the ``integer_widget`` fragment.

.. code-block:: html+php

<!-- templates/form/integer_widget.html.php -->
<!-- src/Resources/integer_widget.html.php -->
<div class="integer_widget">
<?php echo $view['form']->block(
$form,
Expand Down Expand Up @@ -433,7 +433,7 @@ method:

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

Referencing base Form Blocks (Twig specific)
Expand Down Expand Up @@ -750,7 +750,7 @@ customize the ``name`` field only:

<?php echo $view['form']->widget($form['name']); ?>

<!-- templates/form/_product_name_widget.html.php -->
<!-- src/Resources/_product_name_widget.html.php -->
<div class="text_widget">
<?php echo $view['form']->block('form_widget_simple') ?>
</div>
Expand Down Expand Up @@ -808,7 +808,7 @@ You can also override the markup for an entire field row using the same method:

<?php echo $view['form']->row($form['name']); ?>

<!-- templates/form/_product_name_row.html.php -->
<!-- src/Resources/_product_name_row.html.php -->
<div class="name_row">
<?php echo $view['form']->label($form) ?>
<?php echo $view['form']->errors($form) ?>
Expand Down
2 changes: 1 addition & 1 deletion form/form_dependencies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ create your form::
use App\Form\TaskType;

// ...
public function newAction()
public function new()
{
$em = $this->getDoctrine()->getManager();

Expand Down
2 changes: 1 addition & 1 deletion form/form_themes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ do this, create a new template file that will store the new markup:

.. code-block:: html+php

<!-- templates/form/form_row.html.php -->
<!-- src/Resources/form_row.html.php -->
<div class="form_row">
<?php echo $view['form']->label($form, $label) ?>
<?php echo $view['form']->errors($form) ?>
Expand Down
4 changes: 2 additions & 2 deletions form/use_empty_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ How to Configure empty Data for a Form Class
The ``empty_data`` option allows you to specify an empty data set for your
form class. This empty data set would be used if you submit your form, but
haven't called ``setData()`` on your form or passed in data when you created
your form. For example::
your form. For example, in a controller::

public function indexAction()
public function index()
{
$blog = ...;

Expand Down
4 changes: 2 additions & 2 deletions form/without_class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ an array of the submitted data. This is actually really easy::
use Symfony\Component\HttpFoundation\Request;
// ...

public function contactAction(Request $request)
public function contact(Request $request)
{
$defaultData = array('message' => 'Type your message here');
$form = $this->createFormBuilder($defaultData)
Expand Down Expand Up @@ -102,7 +102,7 @@ but here's a short example:
If you are using validation groups, you need to either reference the
``Default`` group when creating the form, or set the correct group on
the constraint you are adding.

.. code-block:: php

new NotBlank(array('groups' => array('create', 'update')));
Expand Down
13 changes: 6 additions & 7 deletions forms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ from inside a controller::

class DefaultController extends Controller
{
public function newAction(Request $request)
public function new(Request $request)
{
// create a task and give it some dummy data for this example
$task = new Task();
Expand Down Expand Up @@ -221,7 +221,7 @@ your controller::
// ...
use Symfony\Component\HttpFoundation\Request;

public function newAction(Request $request)
public function new(Request $request)
{
// just setup a fresh $task object (remove the dummy data)
$task = new Task();
Expand Down Expand Up @@ -338,7 +338,7 @@ object.

.. code-block:: yaml

# src/Resources/config/validation.yml
# config/validation.yaml
App\Entity\Task:
properties:
task:
Expand All @@ -349,7 +349,7 @@ object.

.. code-block:: xml

<!-- src/Resources/config/validation.xml -->
<!-- config/validation.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand Down Expand Up @@ -516,7 +516,7 @@ the type of your field and set it up for you. In this example, Symfony can
guess from the validation rules that both the ``task`` field is a normal
``TextType`` field and the ``dueDate`` field is a ``DateType`` field::

public function newAction()
public function new()
{
$task = new Task();

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

public function newAction()
public function new()
{
$task = ...;
$form = $this->createForm(TaskType::class, $task);
Expand Down Expand Up @@ -708,4 +708,3 @@ Learn more

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