Skip to content

Conversation

MatTheCat
Copy link
Contributor

Follow-up of #21386 (comment)

->name('to_review')
->from(BlogPostStatus::Draft)
->to([BlogPostStatus::Reviewed]);
->from([BlogPostStatus::Draft->value])
Copy link
Member

Choose a reason for hiding this comment

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

is this really needed ? The Yaml code snippet uses the enum case, not the value.

Copy link
Contributor Author

@MatTheCat MatTheCat Oct 14, 2025

Choose a reason for hiding this comment

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

The PHP config would support an enum, but not in an array. Since arrays are used everywhere else I preferred to keep consistency.

Copy link
Member

Choose a reason for hiding this comment

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

This fails with

The following keys are not supported by "Symfony\Config\Framework\Workflows\WorkflowConfig\TransitionConfig\FromConfig": 0 in .../config/packages/workflow.php.

My advice: the array-shape format is way more flexible: it allows to diverge from the shape and still have normalizers make it work. (Which means we can also improve the shape-generator independently)

Copy link
Member

Choose a reason for hiding this comment

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

We could also take this as an opportunity to improve the config generators, so that eg enums are accepted in the place() method. Lists accepted from ->from(). But I don't know if we'd have enough info in the config tree to know about this.
The array-shape format looks the best way to overcome this wall.

Copy link
Member

Choose a reason for hiding this comment

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

all the block works this way

    $blogPublishing->transition()
        ->name('to_review')
            ->from(BlogPostStatus::Draft)
            ->to(BlogPostStatus::Reviewed);

    $blogPublishing->transition()
        ->name('publish')
            ->from(BlogPostStatus::Reviewed)
            ->to(BlogPostStatus::Published);

    $blogPublishing->transition()
        ->name('reject')
            ->from(BlogPostStatus::Reviewed)
            ->to(BlogPostStatus::Rejected);

Copy link
Member

@nicolas-grekas nicolas-grekas Oct 16, 2025

Choose a reason for hiding this comment

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

Related: symfony/symfony#62082, to allow enums in ->from(['place' => Enum::Case])

->property('status');
$blogPublishing->places(BlogPostStatus::cases());
$blogPublishing->place(BlogPostStatus::Draft->value);
Copy link
Member

Choose a reason for hiding this comment

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

this is not the equivalent of the Yaml code snippet, which references the enum itself instead of registering each case separately.

The equivalent of the Yaml snippet would be BlogPostStatus::class

Copy link
Contributor Author

@MatTheCat MatTheCat Oct 14, 2025

Choose a reason for hiding this comment

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

AFAIU there is no equivalent to the YAML syntax using PHP.

Passing BlogPostStatus::class to place would create a place named as the class.

Copy link
Member

Choose a reason for hiding this comment

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

@MatTheCat is right, there's no equivalent using the fluent PHP-DSL

Copy link
Member

Choose a reason for hiding this comment

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

Ah, wait, this works: $blogPublishing->place(BlogPostStatus::class.'::*');

<!-- or type="state_machine" -->
<framework:workflow name="blog_publishing" type="workflow" places="App\Enumeration\BlogPostStatus::*">
<framework:marking-store type="single_state">
<framework:initial-marking>draft</framework:initial-marking>
Copy link
Contributor Author

@MatTheCat MatTheCat Oct 14, 2025

Choose a reason for hiding this comment

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

Not sure why initial-marking is in a sequence; I moved it so that the XML is valid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants