This post will cover how to use a ProcessManger class together with Symfony’s workflow component.
The Process Manager
The ProcessManager is responsible for mapping states with controller routes. This makes it easy for you to know which
controller action that is next in line and ready to be executed.
The ProcessManager class looks like this:
A workflow is very similar to a state machine, containing places and transitions, where places refer to “states”.
To read more about configuring and setting up your own workflow, please see the Symfony documentation
The first thing to do in your controller would be to retrieve your state machine from the service container:
Next, check if the transition you want to apply is available for your object, based on its current state.
If it is, apply it and let Doctrine update the database:
Now comes the interesting part:
After applying the new state, you would also want to redirect the user to the next step. This is where the ProcessManager comes in.
Before you can start using the ProcessManager you have to declare it in services.yml:
The argument sent to the ProcessManager is the specific workflow that we want our ProcessManager to handle.
As we can see in the declaration above, each state has a route name assigned to it. For an example:
The state create_account is mapped to the 'account_register' route name.
Each route name refers to a specific
controller action, and this is handled by annotations.
With the state-to-route mapping, the ProcessManager will always make sure that the users is redirected to the correct controller.
A final example of a controller action would look like this: