From dedf4fe3456aa1e3f54403d9c6b04fa909aae9d0 Mon Sep 17 00:00:00 2001 From: PatrickePatate Date: Thu, 16 Jan 2025 16:15:50 +0100 Subject: [PATCH 1/4] Enhance docs --- docs/guide/upgrading/9.0.md | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/docs/guide/upgrading/9.0.md b/docs/guide/upgrading/9.0.md index 0de32e992..d84a81843 100644 --- a/docs/guide/upgrading/9.0.md +++ b/docs/guide/upgrading/9.0.md @@ -558,12 +558,15 @@ This shouldn’t cause any trouble, as this is a fix, but it could break unortho ## New validation system (and deprecation of the old one) -The validation system was odd, for legacy reasons. -In 9.x, it has been rewritten to be in phase with Laravel and to be more consistent: +The validation system has been revamped in version 9.x to align better with Laravel and improve consistency. Key changes include: -- validation rules can now be defined in a `rules()` method of the form / command class, -- or with a `->validate($data, $rules)` call before update / store. -- The `$formValidatorClass` property usage, in a `SharpForm`, is now deprecated (you are strongly encouraged to migrate to the `rules()` method instead). +- **Defining validation rules**: + - Use the `rules()` method in the form or command class to define validation rules. + - The `rules()` method accepts an optional `$data` parameter (`rules(array $data)`), which represents the validated data (the same data passed to `validate()`). +- **Alternate Validation**: + - You can also validate data using `->validate($data, $rules)` before update or store operations. +- **Form Validators are now Deprecated**: + - The `$formValidatorClass` property in `SharpForm` is deprecated. You are strongly encouraged to switch to the `rules()` method. This code in 8.x: ```php @@ -623,7 +626,7 @@ class PostForm extends SharpForm This version brings two huge benefits (besides the fact that it's clearer): - the "delayed creation" thing is gone (hooray!): the `{id}` parameter in a `SharpFormUploadField` storageBasePath isn't anymore an issue in creation case as Sharp will no longer call the `update()` method twice. -- Validation is now called AFTER data formatters, even in `SharpForm` (it was already the case with `Command`). +- **Validation is now called AFTER data formatters**, even in `SharpForm` (it was already the case with `Command`). **Breaking changes**: the 8.x and below validation is still allowed, but deprecated. @@ -631,6 +634,23 @@ If you decide to migrate (and you should), pay attention to: - remove special workarounds you may have done to handle the "delayed creation" thing, - remove the `.text` suffix you may have added for `SharpFormEditorField` validation rules. +- remove the common `.id` suffix you may have added for `SharpFormAutocomplete(Remote|Local)Field` validation rules. + +Here's a code example (in which editor is a `SharpFormEditorField` and authors is a `SharpFormAutocompleteLocalField`): +```diff +class PostForm extends SharpForm +{ + public function rules(): array + { + return [ + - 'editor.text' => 'required', + + 'editor' => 'required', + - 'authors.id' => 'required', + + 'authors' => 'required', + ]; + } +} +``` **If you decide not to migrate just now**, you should ensure that the `\Code16\Sharp\Http\Middleware\Api\BindSharpValidationResolver` middleware in added to the `api` group: From c16ae8b04088c283e39986743e20555e67b09e15 Mon Sep 17 00:00:00 2001 From: PatrickePatate Date: Thu, 16 Jan 2025 16:17:44 +0100 Subject: [PATCH 2/4] Small fix --- docs/guide/upgrading/9.0.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/guide/upgrading/9.0.md b/docs/guide/upgrading/9.0.md index d84a81843..809897f3a 100644 --- a/docs/guide/upgrading/9.0.md +++ b/docs/guide/upgrading/9.0.md @@ -643,10 +643,10 @@ class PostForm extends SharpForm public function rules(): array { return [ - - 'editor.text' => 'required', - + 'editor' => 'required', - - 'authors.id' => 'required', - + 'authors' => 'required', +- 'editor.text' => 'required', ++ 'editor' => 'required', +- 'authors.id' => 'required', ++ 'authors' => 'required', ]; } } From 8c707b04c5da11b325776cc75e866eb1c8dbdda6 Mon Sep 17 00:00:00 2001 From: PatrickePatate Date: Thu, 16 Jan 2025 16:33:03 +0100 Subject: [PATCH 3/4] Enhance blade-icons docs --- docs/guide/upgrading/9.0.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/guide/upgrading/9.0.md b/docs/guide/upgrading/9.0.md index 809897f3a..8af8fa0a4 100644 --- a/docs/guide/upgrading/9.0.md +++ b/docs/guide/upgrading/9.0.md @@ -175,6 +175,23 @@ And rename old icon names to blade-fontawesome names in your `SharpMenu` : ``` If you were using old fontawesome 4 icons you may need to [rename them](https://docs.fontawesome.com/v5/web/setup/upgrade-from-v4#icon-name-changes-between-version-4-and-5). +#### Restore fontawesome icons default behavior *(optional)* +As the default behavior of `blade-icons` (which uses an `svg` tag) differs from the previous behavior of FontAwesome's `i` tag (which was inline and sized like text), you may need to adjust the `blade-icons` configuration to replicate the original behavior. + +First, publish the FontAwesome blade-icons configuration file: +```bash +php artisan vendor:publish --tag=blade-fontawesome-config +``` + +Then set the default attributes for each FontAwesome classes (solid, regular, brands, and optionally pro) : +```php + 'attributes' => [ + 'width' => '1rem', + 'height' => '1rem', + 'style' => 'display: inline;' + ], +``` + ## No more Bootstrap.css / Font awesome classes You may be using Custom HTML (entity list row, editor embeds, form HTML field, form Autocomplete item template, page alerts) with CSS classes that was present in Sharp 8.x but that don't exist anymore: @@ -184,7 +201,7 @@ You may be using Custom HTML (entity list row, editor embeds, form HTML field, f - Inject a custom CSS file as described [here](../style-visual-theme.md) - If you were using inline Font Awesome icons like `` - Using [blade-fontawesome](https://github.com/owenvoke/blade-fontawesome) component like : ``. In Sharp 9.x all templates are now Blade. - - For `` inside a custom transformer of an EntityList field, you must now do `Blade::render('')` + - For `` inside a custom transformer of an EntityList field, you must now do `Blade::render('')` ## Page Alerts (aka global messages) are not based on Vue templates anymore From 82a1f1b475df48c363dcbd7bc80e8007ef413e37 Mon Sep 17 00:00:00 2001 From: philippe Date: Fri, 17 Jan 2025 10:03:55 +0100 Subject: [PATCH 4/4] Doc --- docs/guide/upgrading/9.0.md | 46 ++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/docs/guide/upgrading/9.0.md b/docs/guide/upgrading/9.0.md index 8af8fa0a4..4bb994784 100644 --- a/docs/guide/upgrading/9.0.md +++ b/docs/guide/upgrading/9.0.md @@ -175,21 +175,29 @@ And rename old icon names to blade-fontawesome names in your `SharpMenu` : ``` If you were using old fontawesome 4 icons you may need to [rename them](https://docs.fontawesome.com/v5/web/setup/upgrade-from-v4#icon-name-changes-between-version-4-and-5). -#### Restore fontawesome icons default behavior *(optional)* -As the default behavior of `blade-icons` (which uses an `svg` tag) differs from the previous behavior of FontAwesome's `i` tag (which was inline and sized like text), you may need to adjust the `blade-icons` configuration to replicate the original behavior. +### Restore fontawesome icons default behavior *(optional)* + +As the default behavior of `blade-icons` (which uses an `svg` tag) differs from the previous behavior of FontAwesome’s `` tag (which was inline and matched the font size), you may need to adjust the `blade-icons` configuration to replicate the original behavior. First, publish the FontAwesome blade-icons configuration file: ```bash php artisan vendor:publish --tag=blade-fontawesome-config ``` -Then set the default attributes for each FontAwesome classes (solid, regular, brands, and optionally pro) : +Then add default attributes for each FontAwesome classes (solid, regular, brands, and optionally pro): ```php - 'attributes' => [ - 'width' => '1rem', - 'height' => '1rem', - 'style' => 'display: inline;' +// file: config/blade-fontawesome.php +return [ + // ... + 'regular' => [ + // ... + 'attributes' => [ + 'width' => '1rem', + 'height' => '1rem', + 'style' => 'display: inline;' + ], ], +]; ``` ## No more Bootstrap.css / Font awesome classes @@ -575,15 +583,13 @@ This shouldn’t cause any trouble, as this is a fix, but it could break unortho ## New validation system (and deprecation of the old one) -The validation system has been revamped in version 9.x to align better with Laravel and improve consistency. Key changes include: +The validation system has been revamped in version 9.x to align better with Laravel and improve consistency. -- **Defining validation rules**: - - Use the `rules()` method in the form or command class to define validation rules. - - The `rules()` method accepts an optional `$data` parameter (`rules(array $data)`), which represents the validated data (the same data passed to `validate()`). -- **Alternate Validation**: - - You can also validate data using `->validate($data, $rules)` before update or store operations. -- **Form Validators are now Deprecated**: - - The `$formValidatorClass` property in `SharpForm` is deprecated. You are strongly encouraged to switch to the `rules()` method. +You may now define your validation rules in two ways: +- implement new `rules()` and `messages()` methods in your `SharpForm` or `Command`; those methods accepts an optional `$formattedData` parameter which represents the... formatted posted data. +- or make a call to `->validate(array $data, array $rules)`. + +In consequence, **Form Validators are now deprecated**: the `$formValidatorClass` property in `SharpForm` is deprecated. You are strongly encouraged to switch to the `rules()` method. This code in 8.x: ```php @@ -643,20 +649,18 @@ class PostForm extends SharpForm This version brings two huge benefits (besides the fact that it's clearer): - the "delayed creation" thing is gone (hooray!): the `{id}` parameter in a `SharpFormUploadField` storageBasePath isn't anymore an issue in creation case as Sharp will no longer call the `update()` method twice. -- **Validation is now called AFTER data formatters**, even in `SharpForm` (it was already the case with `Command`). - -**Breaking changes**: the 8.x and below validation is still allowed, but deprecated. - -If you decide to migrate (and you should), pay attention to: +- **Validation is now called AFTER data formatters**, even in `SharpForm` (it was already the case with `Command`). This cause a breaking change (see below). +**If you decide to migrate** to this new validation system (and you should), pay attention to: - remove special workarounds you may have done to handle the "delayed creation" thing, -- remove the `.text` suffix you may have added for `SharpFormEditorField` validation rules. +- remove the `.text` suffix you may have added for `SharpFormEditorField` validation rules, - remove the common `.id` suffix you may have added for `SharpFormAutocomplete(Remote|Local)Field` validation rules. Here's a code example (in which editor is a `SharpFormEditorField` and authors is a `SharpFormAutocompleteLocalField`): ```diff class PostForm extends SharpForm { + // ... public function rules(): array { return [