@@ -826,6 +826,83 @@ place::
826
826
}
827
827
}
828
828
829
+ Creating Your Own Marking Store
830
+ -------------------------------
831
+
832
+ You may need to implement your own store to execute some additional logic
833
+ when the marking is updated. For example, you may have some specific needs
834
+ to store the marking on certain workflows. To do this, you need to implement
835
+ the
836
+ :class: `Symfony\\ Component\\ Workflow\\ MarkingStore\\ MarkingStoreInterface `::
837
+
838
+ namespace App\Workflow\MarkingStore;
839
+
840
+ use Symfony\Component\Workflow\Marking;
841
+ use Symfony\Component\Workflow\MarkingStore\MarkingStoreInterface;
842
+
843
+ final class BlogPostMarkingStore implements MarkingStoreInterface
844
+ {
845
+ public function getMarking(BlogPost $subject): Marking
846
+ {
847
+ return new Marking([$subject->getCurrentPlace() => 1]);
848
+ }
849
+
850
+ public function setMarking(BlogPost $subject, Marking $marking): void
851
+ {
852
+ $marking = key($marking->getPlaces());
853
+ $subject->setCurrentPlace($marking);
854
+ }
855
+ }
856
+
857
+ Once your marking store is implemented, you can configure your workflow to use
858
+ it:
859
+
860
+ .. configuration-block ::
861
+
862
+ .. code-block :: yaml
863
+
864
+ # config/packages/workflow.yaml
865
+ framework :
866
+ workflows :
867
+ blog_publishing :
868
+ # ...
869
+ marking_store :
870
+ service : ' App\Workflow\MarkingStore\BlogPostMarkingStore'
871
+
872
+ .. code-block :: xml
873
+
874
+ <!-- config/packages/workflow.xml -->
875
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
876
+ <container xmlns =" http://symfony.com/schema/dic/services"
877
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
878
+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
879
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
880
+ http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"
881
+ >
882
+ <framework : config >
883
+ <framework : workflow name =" blog_publishing" >
884
+ <!-- ... -->
885
+ <framework : marking-store service =" App\Workflow\MarkingStore\BlogPostMarkingStore" />
886
+ </framework : workflow >
887
+ </framework : config >
888
+ </container >
889
+
890
+ .. code-block :: php
891
+
892
+ // config/packages/workflow.php
893
+ use App\Workflow\MarkingStore\ReflectionMarkingStore;
894
+ use Symfony\Config\FrameworkConfig;
895
+
896
+ return static function (FrameworkConfig $framework): void {
897
+ // ...
898
+
899
+ $blogPublishing = $framework->workflows()->workflows('blog_publishing');
900
+ // ...
901
+
902
+ $blogPublishing->markingStore()
903
+ ->service(BlogPostMarkingStore::class);
904
+ };
905
+
829
906
Usage in Twig
830
907
-------------
831
908
0 commit comments