From 5d846d71cdb08e20a910a3602aa3ef408ba881c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Fri, 30 Aug 2024 12:02:54 +0200 Subject: [PATCH] [Docs] Disable processing data --- docs/processors.md | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/docs/processors.md b/docs/processors.md index 60f0309d9..333f76f32 100644 --- a/docs/processors.md +++ b/docs/processors.md @@ -3,10 +3,12 @@ Processors process data: send an email, persist to storage, add to queue etc. -* [Default processors](#default-processors) -* [Custom processors](#custom-processors) - * [Sending an email after persisting data](#example-1-sending-an-email-after-persisting-data) - * [Use a custom delete processor](#example-2-use-a-custom-delete-processor) +* [Processors](#processors) + * [Default processors](#default-processors) + * [Custom processors](#custom-processors) + * [Example #1: Sending an email after persisting data](#example-1-sending-an-email-after-persisting-data) + * [Example #2: Use a custom delete processor](#example-2-use-a-custom-delete-processor) + * [Disable processing data](#disable-processing-data) ## Default processors @@ -152,6 +154,37 @@ use Sylius\Resource\Model\ResourceInterface; final class BoardGameResource implements ResourceInterface ``` +## Disable processing data + +In some cases, you may want not to write data. + +For example, you can implement a preview for the updated data without saving them into your storage. + +```php +// src/BoardGameBlog/Infrastructure/Sylius/Resource/BoardGameResource.php + +namespace App\BoardGameBlog\Infrastructure\Sylius\Resource; + +use App\BoardGameBlog\Infrastructure\Sylius\State\Http\Provider\BoardGameItemProvider; +use Sylius\Resource\Metadata\AsResource; +use Sylius\Resource\Metadata\Delete; +use Sylius\Resource\Model\ResourceInterface; + +#[AsResource( + alias: 'app.board_game', + section: 'admin', + formType: BoardGameType::class, + templatesDir: 'crud', + routePrefix: '/admin', +)] +#[Update( + shortName: 'update_preview', + provider: BoardGameItemProvider::class, + write: false, +)] +final class BoardGameResource implements ResourceInterface +``` + **[Go back to the documentation's index](index.md)** **[> Next chapter: Responders](responders.md)**