From 175807f8bc957d1644e8f13820aa215e6860e895 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Sun, 12 Nov 2023 11:39:54 +0100 Subject: [PATCH] [Workflow] Mention the `workflow.marking_store.service` option --- workflow.rst | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/workflow.rst b/workflow.rst index e9e3dff2939..422400476f0 100644 --- a/workflow.rst +++ b/workflow.rst @@ -813,6 +813,83 @@ place:: } } +Creating Your Own Marking Store +------------------------------- + +You may need to implement your own store to execute some additional logic +when the marking is updated. For example, you may have some specific needs +to store the marking on certain workflows. To do this, you need to implement +the +:class:`Symfony\\Component\\Workflow\\MarkingStore\\MarkingStoreInterface`:: + + namespace App\Workflow\MarkingStore; + + use Symfony\Component\Workflow\Marking; + use Symfony\Component\Workflow\MarkingStore\MarkingStoreInterface; + + final class BlogPostMarkingStore implements MarkingStoreInterface + { + public function getMarking(BlogPost $subject): Marking + { + return new Marking([$subject->getCurrentPlace() => 1]); + } + + public function setMarking(BlogPost $subject, Marking $marking): void + { + $marking = key($marking->getPlaces()); + $subject->setCurrentPlace($marking); + } + } + +Once your marking store is implemented, you can configure your workflow to use +it: + +.. configuration-block:: + + .. code-block:: yaml + + # config/packages/workflow.yaml + framework: + workflows: + blog_publishing: + # ... + marking_store: + service: 'App\Workflow\MarkingStore\BlogPostMarkingStore' + + .. code-block:: xml + + + + + + + + + + + + + .. code-block:: php + + // config/packages/workflow.php + use App\Workflow\MarkingStore\ReflectionMarkingStore; + use Symfony\Config\FrameworkConfig; + + return static function (FrameworkConfig $framework): void { + // ... + + $blogPublishing = $framework->workflows()->workflows('blog_publishing'); + // ... + + $blogPublishing->markingStore() + ->service(BlogPostMarkingStore::class); + }; + Usage in Twig -------------