-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Workflow] Add Doctrine type information for multiple state marking stores #19718
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 </workflow/workflow-and-state-machine>` | ||||||
, 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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about this, I'm talking about the |
||||||
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 | ||||||
--------------------------------- | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this contribution, but this comment is a bit confusing to me:
But in the paragraph above we're saying that we need to store this in a JSON type of column.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true. I was trying to say that JSON is the default type inferred by Doctrine, and so one should either not declare any type, or explicitly declare Json type, but not the
simple_array
. How would you phrase that in a simpler way?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could remove the comment and just use the JSON type explicitly in the example. Experienced folks can omit the type if they know that Doctrine will guess it for them.