You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit standardizes whitespace and formatting across several migration guide documentation files for forms, hooks, and testing. No functional or content changes were made; only formatting for improved readability and consistency.
Copy file name to clipboardExpand all lines: development/architecture/migration-guide/forms/CQRS-usage-in-forms.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ weight: 30
8
8
{{% notice note %}}
9
9
This article assumes that you are already familiar with CQRS and [CRUD forms]({{< relref "CRUD-forms" >}}), as this topic only demonstrates the usage of the CQRS approach.
10
10
{{% /notice %}}
11
-
11
+
12
12
## The basics
13
13
14
14
To use CQRS you need to:
@@ -123,9 +123,9 @@ public function create(array $data)
Copy file name to clipboardExpand all lines: development/architecture/migration-guide/forms/CRUD-forms.md
+28-28Lines changed: 28 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,9 +21,9 @@ This guide is intended for core developers and contributors who want to understa
21
21
22
22
In computer programming, _CRUD_ is an acronym for the four basic functions of persistent storage: **create, read, update, and delete**.
23
23
24
-
PrestaShop handles several logic objects, like Cart, Product, Order, Customer... among many others. When such objects are stored using a unique identifier, we refer to them as **identifiable objects**.
24
+
PrestaShop handles several logic objects, like Cart, Product, Order, Customer... among many others. When such objects are stored using a unique identifier, we refer to them as **identifiable objects**.
25
25
26
-
In the Back Office, most identifiable objects are managed using forms and page listings that follow the CRUD pattern. When they do, we refer to those forms as **CRUD Forms**.
26
+
In the Back Office, most identifiable objects are managed using forms and page listings that follow the CRUD pattern. When they do, we refer to those forms as **CRUD Forms**.
27
27
28
28
Since CRUD forms share a lot of common behavior, PrestaShop provides a common pattern to handle them all the same way. It is based on four main elements, each responsible for a very specific task:
29
29
@@ -43,11 +43,11 @@ The _Form Data Provider_ takes care of retrieving data to fill out a form. For t
43
43
{{% funcdef %}}
44
44
45
45
getData(mixed $id): array
46
-
:
46
+
:
47
47
Retrieves data for an edit form, using the given id to retrieve the object's data.
48
48
49
49
getDefaultData(): array
50
-
:
50
+
:
51
51
Returns default data for a creation form.
52
52
53
53
{{% /funcdef %}}
@@ -56,9 +56,9 @@ getDefaultData(): array
56
56
57
57
To create a Form data provider you must implement the following interface:
In the example below, you can see a `ContactFormDataProvider` that queries the database (in this case, using `ObjectModel`) to retrieve data when a specific identifiable object id (in this case, `Contact`) is given, and that returns static data with defaults to use when creating a new element.
61
+
In the example below, you can see a `ContactFormDataProvider` that queries the database (in this case, using `ObjectModel`) to retrieve data when a specific identifiable object id (in this case, `Contact`) is given, and that returns static data with defaults to use when creating a new element.
62
62
63
63
```php
64
64
<?php
@@ -78,7 +78,7 @@ final class ContactFormDataProvider implements FormDataProviderInterface
78
78
public function getData($contactId)
79
79
{
80
80
$contactObjectModel = new Contact($contactId);
81
-
81
+
82
82
// check that the element exists in db
83
83
if (empty($contactObjectModel->id)) {
84
84
throw new PrestaShopObjectNotFoundException('Object not found');
@@ -104,7 +104,7 @@ final class ContactFormDataProvider implements FormDataProviderInterface
104
104
```
105
105
106
106
{{% notice note %}}
107
-
**This example has been simplified for practical reasons.**
107
+
**This example has been simplified for practical reasons.**
108
108
109
109
The core actually uses the CQRS pattern to retrieve data, instead of `ObjectModel`. For more information, have a look at our recommended approach on [how to use CQRS in forms]({{< relref "CQRS-usage-in-forms" >}}).
110
110
{{% /notice %}}
@@ -135,17 +135,17 @@ The _Form Builder_ is used by controllers to build the form that will be shown t
135
135
136
136
It should be enough for most use cases, so you don't need to create it yourself! It also allows your form to be extended by modules.
Generates and returns the Symfony form for an editable object which already exists and can be identified. Additional `$data` and `$options` can be used in your form type.
- The **Form Data Provider**'s service name, that we declared previously.
182
182
183
183
Finally, use it in your controller:
@@ -216,11 +216,11 @@ The _Form Data Handler_ is responsible for persisting the data submitted through
216
216
{{% funcdef %}}
217
217
218
218
create(array $data): mixed
219
-
:
219
+
:
220
220
Creates a new identifiable object using the provided data and returns the created object's id.
221
221
222
222
update(mixed $id, array $data): void
223
-
:
223
+
:
224
224
Updates the object identified by `$id` using the provided data
225
225
226
226
{{% /funcdef %}}
@@ -273,7 +273,7 @@ final class ContactFormDataHandler implements FormDataHandlerInterface
273
273
```
274
274
275
275
{{% notice note %}}
276
-
**This example has been simplified for practical reasons.**
276
+
**This example has been simplified for practical reasons.**
277
277
278
278
The core actually uses the CQRS pattern to retrieve data, instead of `ObjectModel`. For more information, have a look at our recommended approach on [how to use CQRS in forms]({{< relref "CQRS-usage-in-forms" >}}).
279
279
{{% /notice %}}
@@ -297,7 +297,7 @@ use PrestaShop\PrestaShop\Core\Form\IdentifiableObject\DataHandler\FormDataHandl
297
297
298
298
## Form Handler
299
299
300
-
The _Form Handler_ is in charge of validating, enriching and saving submitted form data, using the provided [Form Data Handler](#form-data-handler).
300
+
The _Form Handler_ is in charge of validating, enriching and saving submitted form data, using the provided [Form Data Handler](#form-data-handler).
301
301
302
302
{{% notice tip %}}
303
303
**PrestaShop provides a default implementation for this object.**
**This example has been simplified for practical reasons.**
473
+
**This example has been simplified for practical reasons.**
474
474
475
475
The core actually uses CQRS to handle data persistence, which raises a `DomainException` in case of a constraint error (for example, if the identifiable object you are trying to edit doesn't exist). This is handled in the controller by wrapping the code in a try-catch block, then flashing an error message accordingly.
Copy file name to clipboardExpand all lines: development/architecture/migration-guide/forms/settings-forms.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,7 @@ The idea is to uncouple data management from Controllers, so populating the form
46
46
## Form Handlers
47
47
48
48
Once you are able to manage data loaded to or sent by your forms, you need a way to build those forms (which can be themselves composed of multiple forms).
49
-
49
+
50
50
For this, you need a Form Handler. You can either implement it yourself as a class (based on the interface `PrestaShop\PrestaShop\Core\Form\FormHandlerInterface`), or use PrestaShop's core `FormHandler` to create a service in a declarative way – no need for a new class!
51
51
52
52
As an example, here's how the Administration page's Form Handler service is declared:
After applying this change, access the url of the page you want to migrate. In ``admin-dev/hooks.txt``, you'll see the list of available hooks in the legacy page.
25
-
25
+
26
26
Now, create a simple module that hooks on each one of these hooks and renders something visible that you can retrieve in the new page.
If you need to dispatch a hook from a non-controller class, you'll need to inject the [HookDispatcher](https://github.com/PrestaShop/PrestaShop/blob/8.0.x/src/Core/Hook/HookDispatcher.php) class.
50
-
50
+
51
51
If your class is defined as a Symfony service, the HookDispatcher is available as a service called `prestashop.core.hook.dispatcher`.
0 commit comments