Skip to content

[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

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
38 changes: 38 additions & 0 deletions workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

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:

Type declaration is not mandatory ...

But in the paragraph above we're saying that we need to store this in a JSON type of column.

Copy link
Contributor Author

@Tiriel Tiriel Apr 5, 2024

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?

Copy link
Member

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.

// 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Inside a multiple state marking store, places are store as keys with
Inside a multiple state marking stored, places are store as keys with

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this, I'm talking about the marking_store object.
Going to try for another way to say this, like "Inside a multiple-state marking_store" ?

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
---------------------------------

Expand Down