Skip to content

[Workflow] Mention the workflow.marking_store.service option #19129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,83 @@ place::
}
}

Creating Your Own Marking Store
-------------------------------

You may need to implement your own store to execute some additional logic
when the marking is updated. For example, you may have some specific needs
to store the marking on certain workflows. To do this, you need to implement
the
:class:`Symfony\\Component\\Workflow\\MarkingStore\\MarkingStoreInterface`::

namespace App\Workflow\MarkingStore;

use Symfony\Component\Workflow\Marking;
use Symfony\Component\Workflow\MarkingStore\MarkingStoreInterface;

final class BlogPostMarkingStore implements MarkingStoreInterface
{
public function getMarking(BlogPost $subject): Marking
{
return new Marking([$subject->getCurrentPlace() => 1]);
}

public function setMarking(BlogPost $subject, Marking $marking): void
{
$marking = key($marking->getPlaces());
$subject->setCurrentPlace($marking);
}
}

Once your marking store is implemented, you can configure your workflow to use
it:

.. configuration-block::

.. code-block:: yaml

# config/packages/workflow.yaml
framework:
workflows:
blog_publishing:
# ...
marking_store:
service: 'App\Workflow\MarkingStore\BlogPostMarkingStore'

.. code-block:: xml

<!-- config/packages/workflow.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"
>
<framework:config>
<framework:workflow name="blog_publishing">
<!-- ... -->
<framework:marking-store service="App\Workflow\MarkingStore\BlogPostMarkingStore"/>
</framework:workflow>
</framework:config>
</container>

.. code-block:: php

// config/packages/workflow.php
use App\Workflow\MarkingStore\ReflectionMarkingStore;
use Symfony\Config\FrameworkConfig;

return static function (FrameworkConfig $framework): void {
// ...

$blogPublishing = $framework->workflows()->workflows('blog_publishing');
// ...

$blogPublishing->markingStore()
->service(BlogPostMarkingStore::class);
};

Usage in Twig
-------------

Expand Down