@@ -870,6 +870,83 @@ place::
870870 }
871871 }
872872
873+ Creating Your Own Marking Store
874+ -------------------------------
875+
876+ You may need to implement your own store to execute some additional logic
877+ when the marking is updated. For example, you may have some specific needs
878+ to store the marking on certain workflows. To do this, you need to implement
879+ the
880+ :class: `Symfony\\ Component\\ Workflow\\ MarkingStore\\ MarkingStoreInterface `::
881+
882+ namespace App\Workflow\MarkingStore;
883+
884+ use Symfony\Component\Workflow\Marking;
885+ use Symfony\Component\Workflow\MarkingStore\MarkingStoreInterface;
886+
887+ final class BlogPostMarkingStore implements MarkingStoreInterface
888+ {
889+ public function getMarking(BlogPost $subject): Marking
890+ {
891+ return new Marking([$subject->getCurrentPlace() => 1]);
892+ }
893+
894+ public function setMarking(BlogPost $subject, Marking $marking): void
895+ {
896+ $marking = key($marking->getPlaces());
897+ $subject->setCurrentPlace($marking);
898+ }
899+ }
900+
901+ Once your marking store is implemented, you can configure your workflow to use
902+ it:
903+
904+ .. configuration-block ::
905+
906+ .. code-block :: yaml
907+
908+ # config/packages/workflow.yaml
909+ framework :
910+ workflows :
911+ blog_publishing :
912+ # ...
913+ marking_store :
914+ service : ' App\Workflow\MarkingStore\BlogPostMarkingStore'
915+
916+ .. code-block :: xml
917+
918+ <!-- config/packages/workflow.xml -->
919+ <?xml version =" 1.0" encoding =" UTF-8" ?>
920+ <container xmlns =" http://symfony.com/schema/dic/services"
921+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
922+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
923+ xsi : schemaLocation =" http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
924+ http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"
925+ >
926+ <framework : config >
927+ <framework : workflow name =" blog_publishing" >
928+ <!-- ... -->
929+ <framework : marking-store service =" App\Workflow\MarkingStore\BlogPostMarkingStore" />
930+ </framework : workflow >
931+ </framework : config >
932+ </container >
933+
934+ .. code-block :: php
935+
936+ // config/packages/workflow.php
937+ use App\Workflow\MarkingStore\ReflectionMarkingStore;
938+ use Symfony\Config\FrameworkConfig;
939+
940+ return static function (FrameworkConfig $framework): void {
941+ // ...
942+
943+ $blogPublishing = $framework->workflows()->workflows('blog_publishing');
944+ // ...
945+
946+ $blogPublishing->markingStore()
947+ ->service(BlogPostMarkingStore::class);
948+ };
949+
873950 Usage in Twig
874951-------------
875952
0 commit comments