Just load the WorkflowPass
compiler pass and the services.yaml
in your project.
After that, when a class supports workflow it'll have two routes (assuming entity dummy
):
api_dummies_state_item PATCH ANY ANY /api/dummies/{id}/state.{_format}
PATCH
with data (must be state
key) {"state": "state_name"}
to change a given resource's state to state_name
.
api_dummies_state_get_item GET ANY ANY /api/dummies/{id}/state.{_format}
GET
receives available states for the given resource.
Hi @soyuka !
Thanks for this gist.
I'm using it in a SF5.2 + PHP8.0 project and I had to update a few things:
in WorkflowEnabledTransitionsListener.php :
It makes use of
Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent
that is deprecated since SF 4.3 in favor ofSymfony\Component\HttpKernel\Event\ViewEvent
cf. https://symfony.com/doc/4.3/components/http_kernel.html#component-http-kernel-event-table
in WorkflowStateListener.php :
It makes use of
Symfony\Component\HttpKernel\Event\GetResponseEvent
that is deprecated since SF 4.3 in favor ofSymfony\Component\HttpKernel\Event\RequestEvent
cf. https://symfony.com/doc/4.3/components/http_kernel.html#component-http-kernel-event-table
in WorkflowOperationResourceMetadataFactory.php :
Having the optional
$supportsWorkflow
parameter before the mandatory parameter in the constructor is deprecated in PHP8.0. I just switch the order of the arguments in the file. Implying switching the order in services.yaml and thus in WorkflowPass.php replacing the argument index line 27 :$factory->setArgument(1, $arguments);
.cf. https://php.watch/versions/8.0/deprecate-required-param-after-optional