From 82afb3167f53c03f8d104ca62618b17d68e5686f Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Sun, 26 Nov 2017 18:51:28 +0100 Subject: [PATCH 1/2] Updated form/* articles to Symfony 4 --- form/action_method.rst | 4 ++-- form/create_form_type_extension.rst | 7 +++++-- form/direct_submit.rst | 4 ++-- form/dynamic_form_modification.rst | 14 +++++++------- form/form_collections.rst | 12 ++++++------ form/form_customization.rst | 4 ++-- form/form_dependencies.rst | 2 +- form/use_empty_data.rst | 4 ++-- form/without_class.rst | 4 ++-- forms.rst | 11 +++++------ 10 files changed, 34 insertions(+), 32 deletions(-) diff --git a/form/action_method.rst b/form/action_method.rst index 2cea4ab8226..132d766ea4b 100644 --- a/form/action_method.rst +++ b/form/action_method.rst @@ -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')) @@ -83,7 +83,7 @@ options: class DefaultController extends Controller { - public function newAction() + public function new() { // ... diff --git a/form/create_form_type_extension.rst b/form/create_form_type_extension.rst index cc2eefd8fa5..d1f11d7303b 100644 --- a/form/create_form_type_extension.rst +++ b/form/create_form_type_extension.rst @@ -71,6 +71,7 @@ your class as a service and using the ``form.type_extension`` tag: .. code-block:: yaml + # config/services.yaml services: # ... @@ -80,6 +81,7 @@ your class as a service and using the ``form.type_extension`` tag: .. code-block:: xml + + widget($form) ?> diff --git a/form/direct_submit.rst b/form/direct_submit.rst index 855043affc5..d80a96e8db3 100644 --- a/form/direct_submit.rst +++ b/form/direct_submit.rst @@ -10,7 +10,7 @@ submissions:: use Symfony\Component\HttpFoundation\Request; // ... - public function newAction(Request $request) + public function new(Request $request) { $form = $this->createFormBuilder() // ... @@ -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() // ... diff --git a/form/dynamic_form_modification.rst b/form/dynamic_form_modification.rst index b537f89a462..5be39c2fdb0 100644 --- a/form/dynamic_form_modification.rst +++ b/form/dynamic_form_modification.rst @@ -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); @@ -392,7 +392,7 @@ sport like this:: { $builder ->add('sport', EntityType::class, array( - 'class' => 'App:Sport', + 'class' => 'App\Entity\Sport', 'placeholder' => '', )) ; @@ -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, )); @@ -456,7 +456,7 @@ The type would now look like:: { $builder ->add('sport', EntityType::class, array( - 'class' => 'App:Sport', + 'class' => 'App\Entity\Sport', 'placeholder' => '', )); ; @@ -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, )); @@ -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); @@ -578,7 +578,7 @@ field according to the current selection in the ``sport`` field: .. code-block:: html+php - + start($form) ?> row($form['sport']) ?> row($form['position']) ?> diff --git a/form/form_collections.rst b/form/form_collections.rst index 9ef213d8fb5..97a88e72117 100644 --- a/form/form_collections.rst +++ b/form/form_collections.rst @@ -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(); @@ -215,7 +215,7 @@ zero tags when first created). .. code-block:: html+php - + @@ -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); @@ -510,7 +510,7 @@ you will learn about next!). .. code-block:: yaml - # src/Resources/config/doctrine/Task.orm.yml + # src/Resources/config/doctrine/Task.orm.yaml App\Entity\Task: type: entity # ... @@ -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 @@ -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); diff --git a/form/form_customization.rst b/form/form_customization.rst index a80de5f7f50..5a2dca5d578 100644 --- a/form/form_customization.rst +++ b/form/form_customization.rst @@ -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" %} {# ... #} @@ -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) diff --git a/form/form_dependencies.rst b/form/form_dependencies.rst index b953156923f..b39b409538c 100644 --- a/form/form_dependencies.rst +++ b/form/form_dependencies.rst @@ -34,7 +34,7 @@ create your form:: use App\Form\TaskType; // ... - public function newAction() + public function new() { $em = $this->getDoctrine()->getManager(); diff --git a/form/use_empty_data.rst b/form/use_empty_data.rst index 482983ecdb1..1e30e3d0f3a 100644 --- a/form/use_empty_data.rst +++ b/form/use_empty_data.rst @@ -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 = ...; diff --git a/form/without_class.rst b/form/without_class.rst index f40704b61e2..74ca8589999 100644 --- a/form/without_class.rst +++ b/form/without_class.rst @@ -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) @@ -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'))); diff --git a/forms.rst b/forms.rst index 6390e53896e..a0eb4dc9105 100644 --- a/forms.rst +++ b/forms.rst @@ -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(); @@ -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(); @@ -338,7 +338,7 @@ object. .. code-block:: yaml - # src/Resources/config/validation.yml + # src/Resources/config/validation.yaml App\Entity\Task: properties: task: @@ -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(); @@ -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); @@ -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 From 010f78068048a5eaf5e6147d3723b2da72ab2ee4 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 27 Nov 2017 10:18:01 +0100 Subject: [PATCH 2/2] Fixed some issues --- form/create_custom_field_type.rst | 2 +- form/create_form_type_extension.rst | 2 +- form/form_collections.rst | 2 +- form/form_customization.rst | 6 +++--- form/form_themes.rst | 2 +- forms.rst | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/form/create_custom_field_type.rst b/form/create_custom_field_type.rst index 936591f627f..fe9633084a1 100644 --- a/form/create_custom_field_type.rst +++ b/form/create_custom_field_type.rst @@ -141,7 +141,7 @@ link for details), create a ``shipping_widget`` block to handle this: .. code-block:: html+php - +
    block($form, 'widget_container_attributes') ?>> diff --git a/form/create_form_type_extension.rst b/form/create_form_type_extension.rst index d1f11d7303b..877c99e28f7 100644 --- a/form/create_form_type_extension.rst +++ b/form/create_form_type_extension.rst @@ -236,7 +236,7 @@ Specifically, you need to override the ``file_widget`` block: .. code-block:: html+php - + widget($form) ?> diff --git a/form/form_collections.rst b/form/form_collections.rst index 97a88e72117..91a2acaa772 100644 --- a/form/form_collections.rst +++ b/form/form_collections.rst @@ -510,7 +510,7 @@ you will learn about next!). .. code-block:: yaml - # src/Resources/config/doctrine/Task.orm.yaml + # src/Resources/config/doctrine/Task.orm.yml App\Entity\Task: type: entity # ... diff --git a/form/form_customization.rst b/form/form_customization.rst index 5a2dca5d578..fd24220cb45 100644 --- a/form/form_customization.rst +++ b/form/form_customization.rst @@ -401,7 +401,7 @@ file in order to customize the ``integer_widget`` fragment. .. code-block:: html+php - +
    block( $form, @@ -750,7 +750,7 @@ customize the ``name`` field only: widget($form['name']); ?> - +
    block('form_widget_simple') ?>
    @@ -808,7 +808,7 @@ You can also override the markup for an entire field row using the same method: row($form['name']); ?> - +
    label($form) ?> errors($form) ?> diff --git a/form/form_themes.rst b/form/form_themes.rst index 1d2123c6b71..dbc9f35bc0c 100644 --- a/form/form_themes.rst +++ b/form/form_themes.rst @@ -41,7 +41,7 @@ do this, create a new template file that will store the new markup: .. code-block:: html+php - +
    label($form, $label) ?> errors($form) ?> diff --git a/forms.rst b/forms.rst index a0eb4dc9105..cb64643fc17 100644 --- a/forms.rst +++ b/forms.rst @@ -338,7 +338,7 @@ object. .. code-block:: yaml - # src/Resources/config/validation.yaml + # config/validation.yaml App\Entity\Task: properties: task: @@ -349,7 +349,7 @@ object. .. code-block:: xml - +