Skip to content

Plot Branching Navigation

Chris Yates edited this page Aug 11, 2023 · 3 revisions

Plot Branching Navigation (PBN) allows different "paths" to be taken through the steps depending on the response to a step. This is often found in surveys, e.g. go to Q10 if you answered "Yes", go to Q15 if you answered "No".

The steps array defines all possible branches, branches being nested arrays:

$this
    ->wizard
    ->withSteps([
        'step_1',
        'step_2',
        'cat_or_dog',
        [
            'cat' => ['cat_1', 'cat_2', 'cat_3'],
            'dog' => ['dog_1', 'dog_2', 'dog_3', 'dog_4'],
        ],
        'step_5',
    ])
;

Branching

The step event handler defines which branches to use by calling Step::setBranches(). For example, if the user selected in the dog the cat_or_dog step, the step event handler would:

$event->setBranches([
    'cat' => Wizard::BRANCH_DISABLE,
    'dog' => Wizard::BRANCH_ENABLE
]);

Clone this wiki locally