Skip to content
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

Custom Flow Transition? #67

Open
havvg opened this issue Jul 10, 2013 · 2 comments
Open

Custom Flow Transition? #67

havvg opened this issue Jul 10, 2013 · 2 comments

Comments

@havvg
Copy link
Contributor

havvg commented Jul 10, 2013

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>&nbsp;
        {{- (prefix ~ 'skip')|trans -}}
    </button>
{% endif %}

<button type="submit" class="btn btn-success btn-large pull-right">
    <i class="icon-circle-arrow-right"></i>&nbsp;
    {{- (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>&nbsp;
        {{- (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?

@lfjeff
Copy link

lfjeff commented Aug 30, 2013

Would the ability to return to a specific step solve your problem?
take a look at issue #82

@craue
Copy link
Owner

craue commented Jun 23, 2015

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.

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

No branches or pull requests

3 participants