Skip to content

Commit bfd678e

Browse files
committed
feature symfony#19129 [Workflow] Mention the workflow.marking_store.service option (alexandre-daubois)
This PR was merged into the 5.4 branch. Discussion ---------- [Workflow] Mention the `workflow.marking_store.service` option I just discovered this option when trying to implement an enum marking store and make it work. The `service` option is indeed referenced here: https://symfony.com/doc/current/reference/configuration/framework.html#marking-store but it isn't explained how to use it. I propose to add this section which could help a lot Friendly ping `@lyrixx` if you'd like to check 🙂 Commits ------- 175807f [Workflow] Mention the `workflow.marking_store.service` option
2 parents e1d8df7 + 175807f commit bfd678e

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

workflow.rst

+77
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,83 @@ place::
813813
}
814814
}
815815

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+
816893
Usage in Twig
817894
-------------
818895

0 commit comments

Comments
 (0)