Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Workflow] Fix code blocks using an enum#21499

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Closed
Changes fromall 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
25 changes: 14 additions & 11 deletionsworkflow.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -361,11 +361,11 @@
<framework:config>
<!-- 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
ContributorAuthor

@MatTheCatMatTheCatOct 14, 2025
edited
Loading

Choose a reason for hiding this comment

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

Not sure whyinitial-marking is ina sequence; I moved it so that the XML is valid.

<framework:marking-store type="method">
<framework:argument>status</framework:argument>
</framework:marking-store>
<framework:support>App\Entity\BlogPost</framework:support>
<framework:initial-marking>draft</framework:initial-marking>

<framework:transition name="to_review">
<framework:from>draft</framework:from>
Expand All@@ -391,33 +391,36 @@
use Symfony\Config\FrameworkConfig;

return static function (FrameworkConfig $framework): void {
$blogPublishing = $framework->workflows()->workflows('blog_publishing');
$blogPublishing = $framework->workflows()->workflow('blog_publishing');
$blogPublishing
->type('workflow')
->supports([BlogPost::class])
->initialMarking([BlogPostStatus::Draft]);
->initialMarking([BlogPostStatus::Draft->value]);

$blogPublishing->markingStore()
->type('method')
->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 isnot 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 beBlogPostStatus::class

Copy link
ContributorAuthor

@MatTheCatMatTheCatOct 14, 2025
edited
Loading

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.

PassingBlogPostStatus::class toplace would create a place named as the class.

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

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.'::*');

$blogPublishing->place(BlogPostStatus::Reviewed->value);
$blogPublishing->place(BlogPostStatus::Published->value);
$blogPublishing->place(BlogPostStatus::Rejected->value);

$blogPublishing->transition()
->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
ContributorAuthor

@MatTheCatMatTheCatOct 14, 2025
edited
Loading

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.

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)

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 theplace() 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.

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-grekasnicolas-grekasOct 16, 2025
edited
Loading

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

->to([BlogPostStatus::Reviewed->value]);

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

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

Check failure on line 423 in workflow.rst

View workflow job for this annotation

GitHub Actions/ Code Blocks

[Cache Warmup] 2025-10-14T09:24:39+00:00 [critical] Uncaught Error: Class "App\Enumeration\BlogPostStatus" not found

The component will now transparently cast the enum to its backing value
when needed and vice-versa when working with your objects::
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp