State machine transitions
The Sylius Stack lets you leverage Symfony Workflow to apply state machine transitions directly from your grids or Twig templates using actions. If you're not familiar with workflows and state machines in Symfony, read this article.
Install Symfony Workflow
You need to install Symfony Workflow
composer require symfony/workflowExample workflow configuration
Then, you need to set up your own workflow. In this example, we will assume a speaker can submit an application for a talk at a conference (the famous "Call for Papers" !).
An application for a talk starts a draft, then it can be submitted by the speaker.
In this admin interface, we will "allow" admin users to either :
acceptan applicationrejectan applicationput an application on a
waiting listcancelan application (this action could possibly be done by the speaker themselves too if they couldn't make it anymore to the conference event)
Symfony workflow config
We therefore need to register our config. This is done in config/packages/workflow.yaml.
For the purpose of this example, we've placed the config in a separate PHP file, which we then imported in config/packages/workflow.yaml this way :
Create a Resource and Grid
Now, we need to create a Sylius resource and a Sylius grid to manage our Applications.
First, let's create an Application resource :
The resource is linked up to a standard Sylius Grid :
State machine transition operations
To enable your state machine transitions, you need to add an ApplyStateMachineTransition operation for each of the operations you want to enable on your Resource.
This will generate the necessary routes. Let's make sure our routes are properly enabled :

State machine transition actions
Actions in Grids
Once the operation has been added to your Resource, you can simply add an ApplyTransitionAction button on your grid.
The Sylius Stack will automatically enable your state machine transition action if the action can be executed according to the workflow configuration you set up.

Actions in Twig templates
You can also include your transition button actions in any Twig template by leveraging the workflow_can function. The button will only be generated when your Symfony Workflow config allows it.
Last updated
Was this helpful?