8000 [Workflow] Mention the `workflow.marking_store.service` option · symfony/symfony-docs@e2a0b7f · GitHub
[go: up one dir, main page]

Skip to content

Commit e2a0b7f

Browse files
[Workflow] Mention the workflow.marking_store.service option
1 parent 6fb8828 commit e2a0b7f

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

workflow.rst

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,98 @@ 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+
class ReflectionMarkingStore implements MarkingStoreInterface
831+
{
832+
/**
833+
* @var string
834+
*/
835+
private $property;
836+
837+
public function __construct(string $property = 'property')
838+
{
839+
$this->property = $property;
840+
}
841+
842+
public function getMarking(object $subject): Marking
843+
{
844+
$r = new \ReflectionObject($subject);
845+
$property = $r->getProperty($this->property);
846+
847+
return new Marking([$property->getValue($subject) => 1]);
848+
}
849+
850+
public function setMarking(object $subject, Marking $marking): void
851+
{
852+
$r = new \ReflectionObject($subject);
853+
$property = $r->getProperty($this->property);
854+
855+
$property->setValue($subject, $marking);
856+
}
857+
}
858+
859+
Once your marking store is implemented, you can configure your workflow to use
860+
it:
861+
862+
.. configuration-block::
863+
864+
.. code-block:: yaml
865+
866+
# config/packages/workflow.yaml
867+
framework:
868+
workflows:
869+
blog_publishing:
870+
# ...
871+
marking_store:
872+
service: 'App\Workflow\MarkingStore\ReflectionMarkingStore'
873+
874+
.. code-block:: xml
875+
876+
<!-- config/packages/workflow.xml -->
877+
<?xml version="1.0" encoding="UTF-8" ?>
878+
<container xmlns="http://symfony.com/schema/dic/services"
879+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
880+
xmlns:framework="http://symfony.com/schema/dic/symfony"
881+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
882+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"
883+
>
884+
<framework:config>
885+
<framework:workflow name="blog_publishing">
886+
<!-- ... -->
887+
<framework:marking-store service="App\Workflow\MarkingStore\ReflectionMarkingStore"/>
888+
</framework:workflow>
889+
</framework:config>
890+
</container>
891+
892+
.. code-block:: php
893+
894+
// config/packages/workflow.php
895+
use App\Workflow\MarkingStore\ReflectionMarkingStore;
896+
use Symfony\Config\FrameworkConfig;
897+
898+
return static function (FrameworkConfig $framework): void {
899+
// ...
900+
901+
$blogPublishing = $framework->workflows()->workflows('blog_publishing');
902+
// ...
903+
904+
$blogPublishing->markingStore()
905+
->service(ReflectionMarkingStore::class);
906+
};
907+
816908
Usage in Twig
817909
-------------
818910

0 commit comments

Comments
 (0)
{"resolvedServerColorMode":"day"}
0