Custom Flow Transition?
I want to add a custom transition to a form flow. The one I currently require is very simple, but there might be more complex transitions. I'm not even sure, whether this is a good way to accomplish it. I got a flow, which got a step, that allows the user to choose whether to skip a defined part (multiple steps) of the flow.
Flow with custom transition:
class UpdateLeadFormFlow extends AbstractFormFlow
{
const TRANSITION_SKIP_EDITOR = 'skip_editor';
protected function loadStepsConfig()
{
$fnSkipEditor = function($step, UpdateLeadFormFlow $flow) {
return UpdateLeadFormFlow::TRANSITION_SKIP_EDITOR === $flow->getRequestedTransition();
};
return [
[
// The first step, allowing to continue with 2nd or 5th step.
],
[
// ..
'skip' => $fnSkipEditor,
],
[
// ..
'skip' => $fnSkipEditor,
],
[
// ..
'skip' => $fnSkipEditor,
],
[
// ..
],
];
}
// ...
}
The buttons.html.twig in use:
{% trans_default_domain "leads" %}
{% set prefix = 'update_lead.form_actions.step_' ~ flow.currentStepNumber ~ '.' %}
{% if flow.currentStepNumber == flow.firstStepNumber %}
<button type="submit" class="btn btn-success btn-large pull-right" name="{{ flow.formTransitionKey }}" value="skip_editor">
<i class="icon-circle-arrow-right"></i>
{{- (prefix ~ 'skip')|trans -}}
</button>
{% endif %}
<button type="submit" class="btn btn-success btn-large pull-right">
<i class="icon-circle-arrow-right"></i>
{{- (prefix ~ 'submit')|trans -}}
</button>
{% if flow.currentStepNumber in (flow.firstStepNumber + 1) .. flow.lastStepNumber %}
<button type="submit" class="btn btn-large pull-right" name="{{ flow.formTransitionKey }}" value="back" formnovalidate>
<i class="icon-circle-arrow-left"></i>
{{- (prefix ~ 'back')|trans -}}
</button>
{% endif %}
The thing I don't like is the unnecessary coupling customization of the template for the custom transition.
I would rather like to have a collection of transitions that are available on a given step. This collection contains the two default transitions already given reset and back. Each step may return a collection of additional transitions to be handled.
If a transition is active, the flow will handle it, e.g. by firing an event to delegate the changes in state. This would also allow to hook into resetting a flow or going backwards.
What are your thoughts? Am I missing some key elements to accomplish what I require? Are transitions the right way?
Would the ability to return to a specific step solve your problem? take a look at issue https://github.com/craue/CraueFormFlowBundle/issues/82
Looks like this isn't easy to implement. I'd like to postpone it for a future version (if at all) in order to release 3.0.0 sometime soon.