From 2f65b0027202bc18a083f9f87c851607da9a4dbd Mon Sep 17 00:00:00 2001 From: Benjamin Zaslavsky Date: Wed, 27 Mar 2024 16:30:42 +0100 Subject: [PATCH 1/2] [Workflow] Add type information for multiple state marking store --- workflow.rst | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/workflow.rst b/workflow.rst index 422400476f0..cd2d9ebd3c5 100644 --- a/workflow.rst +++ b/workflow.rst @@ -248,6 +248,44 @@ what actions are allowed on a blog post:: // See a specific available transition for the post in the current state $transition = $workflow->getEnabledTransition($post, 'publish'); +Using a multiple state marking store +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +If you are creating a :doc:`workflow ` +, your marking store may need to contain multiple places at the same time. +If you are using Doctrine, the matching column definition should use the +type ``json`` :: + + // src/Entity/BlogPost.php + namespace App\Entity; + + use Doctrine\DBAL\Types\Types; + use Doctrine\ORM\Mapping as ORM; + + #[ORM\Entity] + class BlogPost + { + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column] + private int $id; + + // Type declaration is not mandatory and + // matches the guessed value from Doctrine + #[ORM\Column(type: Types::JSON)] // or #[ORM\Column(type: 'json')] + private array $currentPlaces; + + // ... + } + +.. tip:: + + You should not use the type ``simple_array`` for your marking store. + Inside a multiple state marking store, places are store as keys with + a value of one, such as ``['draft' => 1]``. If the marking store contains + only one place, this Doctrine type will store its value only as a string, + resulting in the loss of the object's current place. + Accessing the Workflow in a Class --------------------------------- From 85268b49b3bf7aa9e711a35d40047b814bc36931 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 9 Apr 2024 17:10:00 +0200 Subject: [PATCH 2/2] Minor tweaks --- workflow.rst | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/workflow.rst b/workflow.rst index cd2d9ebd3c5..04e8eb18ef5 100644 --- a/workflow.rst +++ b/workflow.rst @@ -251,10 +251,9 @@ what actions are allowed on a blog post:: Using a multiple state marking store ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -If you are creating a :doc:`workflow ` -, your marking store may need to contain multiple places at the same time. -If you are using Doctrine, the matching column definition should use the -type ``json`` :: +If you are creating a :doc:`workflow `, +your marking store may need to contain multiple places at the same time. That's why, +if you are using Doctrine, the matching column definition should use the type ``json``:: // src/Entity/BlogPost.php namespace App\Entity; @@ -270,21 +269,19 @@ type ``json`` :: #[ORM\Column] private int $id; - // Type declaration is not mandatory and - // matches the guessed value from Doctrine - #[ORM\Column(type: Types::JSON)] // or #[ORM\Column(type: 'json')] + #[ORM\Column(type: Types::JSON)] private array $currentPlaces; // ... } -.. tip:: +.. caution:: - You should not use the type ``simple_array`` for your marking store. - Inside a multiple state marking store, places are store as keys with - a value of one, such as ``['draft' => 1]``. If the marking store contains - only one place, this Doctrine type will store its value only as a string, - resulting in the loss of the object's current place. + You should not use the type ``simple_array`` for your marking store. Inside + a multiple state marking store, places are stored as keys with a value of one, + such as ``['draft' => 1]``. If the marking store contains only one place, + this Doctrine type will store its value only as a string, resulting in the + loss of the object's current place. Accessing the Workflow in a Class ---------------------------------