Skip to content

Commit 989ff12

Browse files
author
sd-lueckel
authored
Merge pull request #2 from solutionDrive/redirect-to-first-step-if-no-slug-passed
New route redirecting to first step
2 parents a5b5a36 + 545a042 commit 989ff12

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Controller/MultiStepController.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use solutionDrive\MultiStepBundle\Registry\MultiStepFlowRegistryInterface;
1313
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
14+
use Symfony\Component\HttpFoundation\RedirectResponse;
1415
use Symfony\Component\HttpFoundation\Request;
1516
use Symfony\Component\HttpFoundation\Response;
1617
use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
@@ -95,4 +96,17 @@ public function stepAction(Request $request, string $flow_slug, string $step_slu
9596

9697
return call_user_func_array($callableController, $arguments);
9798
}
99+
100+
public function firstStepAction(string $flow_slug): Response
101+
{
102+
$flow = $this->flowRegistry->getFlowBySlug($flow_slug);
103+
$firstStep = $flow->getFirstStep();
104+
$router = $this->get('router');
105+
$firstStepLink = $router->generate(
106+
'sd_multistep',
107+
['flow_slug' => $flow_slug, 'step_slug' => $firstStep->getSlug()]
108+
);
109+
110+
return new RedirectResponse($firstStepLink);
111+
}
98112
}

src/Resources/config/routing.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ sd_multistep:
44
flow_slug: ^[^/]+$
55
step_slug: ^[^/]+$
66
controller: sd.multistep.controller:stepAction
7+
sd_multistep_start:
8+
path: /
9+
requirements:
10+
flow_slug: ^[^/]+$
11+
controller: sd.multistep.controller:firstStepAction
712

813
# May be used in future? Not implemented yet, but should be noted here...
914
#sd_multistep_with_parameters:

0 commit comments

Comments
 (0)