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