Skip to content

[Workflow] Use Enum as places #57193

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

Closed
kira0269 opened this issue May 27, 2024 · 4 comments
Closed

[Workflow] Use Enum as places #57193

kira0269 opened this issue May 27, 2024 · 4 comments
Labels

Comments

@kira0269
Copy link

Description

Workflow yaml configuration waits for string values to configure places and transitions. Also, the marking store key needs a property/method to access.

Since enums exist, I think using them for workflows fits pretty well.
But the only way to achieve this is by following what's described here : https://www.strangebuzz.com/en/blog/using-php-enumerations-with-your-symfony-workflows

Places
I suggest to make enums compatible with the workflow component based on these rules:

  • Only backed string enum or simple Enum could be used. For Enum, use the name of the case (snake case ?)
  • An enum can be put as "places" config. Each value would be a place.
  • The marking_store config section would accept a new type: 'enum'. In this case, a new EnumMarkingStore would be instantiated

Transitions
For transitions, maybe a new way to configure them could be better with enums.
Before

framework:
    workflows:
        blog_publishing:
            transitions:
                to_review:
                    from: draft
                    to:   reviewed
                publish:
                    from: reviewed
                    to:   published
                reject:
                    from: reviewed
                    to:   rejected

After

# config/packages/workflow.yaml
framework:
    workflows:
        blog_publishing:
            transitions:
                -  name: !php/enum BlogPublishingTransitions::REVIEW
                    from: draft
                    to:   reviewed
                -  name: !php/enum BlogPublishingTransitions::PUBLISH
                    from: reviewed
                    to:   published
                -  name: !php/enum BlogPublishingTransitions::REJECT
                    from: reviewed
                    to:   rejected

Please feel free to give me your point of view about this idea.
I would be glad to contribute on this feature if you think it's relevant 😃

Example

Example of new workflow config:

# config/packages/workflow.yaml
framework:
    workflows:
        blog_publishing:
            type: 'workflow' # or 'state_machine'
            audit_trail:
                enabled: true
            marking_store:
                type: 'enum'
                property: 'currentPlace'
            supports:
                - App\Entity\BlogPost
            initial_marking: draft
            places: App\BlogPostState
            transitions:
                -  name: !php/enum App\BlogPostTransition::REVIEW
                    from: !php/enum App\BlogPostState::DRAFT
                    to:   !php/enum App\BlogPostState::REVIEWED
                -  name: !php/enum App\BlogPostTransition::PUBLISH
                    from: !php/enum App\BlogPostState::REVIEWED
                    to:   !php/enum App\BlogPostState::PUBLISHED
                -  name: !php/enum App\BlogPostTransition::REJECT
                    from: !php/enum App\BlogPostState::REVIEWED
                    to:   !php/enum App\BlogPostState::REJECTED
# src/BlogPostTransition.php
enum BlogPostTransition: string
{
    case REVIEW = 'review';
    case PUBLISH = 'publish';
    case REJECT = 'reject';
}
# src/BlogPostState.php
enum BlogPostState: string
{
    case DRAFT = 'draft';
    case REVIEWED = 'reviewed';
    case PUBLISHED = 'published';
    case REJECTED = 'rejected';
}
@derrabus
Copy link
Member

Did you search for earlier issues and PRs on that topic?

@xabbuh
Copy link
Member

xabbuh commented May 27, 2024

see #44211 and #54582

@kira0269
Copy link
Author

kira0269 commented May 27, 2024

Did you search for earlier issues and PRs on that topic?

My bad, I looked into issues (apparently not well), not PRs ^^"

@derrabus
Copy link
Member

Closing as duplicate of #44211.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants