Skip to content

Commit 47c1177

Browse files
committed
[Funnel] Add flag to state if entity is live
1 parent 4934135 commit 47c1177

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/Parthenon/Funnel/Funnel.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ final class Funnel implements FunnelInterface
4747
private FormFactoryInterface $formFactory;
4848
private SuccessHandlerInterface $successHandler;
4949
private SkipHandlerInterface $skipHandler;
50-
5150
private SessionInterface $session;
51+
private bool $isLiveEntity = false;
5252

5353
public function __construct(FormFactoryInterface $formFactory, RequestStack $requestStack)
5454
{
@@ -91,6 +91,13 @@ public function setSuccessHandler(SuccessHandlerInterface $successHandler): self
9191
return $this;
9292
}
9393

94+
public function isLiveEntity(bool $preloaded): self
95+
{
96+
$this->isLiveEntity = $preloaded;
97+
98+
return $this;
99+
}
100+
94101
public function process(Request $request)
95102
{
96103
if (!is_object($this->entity)) {
@@ -102,7 +109,7 @@ public function process(Request $request)
102109

103110
$funnelState = $this->getState($newState);
104111

105-
$entity = $funnelState->getEntity();
112+
$entity = $this->isLiveEntity ? $this->entity : $funnelState->getEntity();
106113

107114
if (null !== $request->get('skip', null)) {
108115
return $this->handleSkip($entity);
@@ -212,7 +219,7 @@ private function getState(bool $newState): FunnelState
212219
private function saveState(FunnelState $funnelState)
213220
{
214221
$this->getLogger()->info('Saving funnel state', ['entity' => get_class($this->entity)]);
215-
$this->session->set(get_class($this->entity).'_funnel', $funnelState);
222+
$this->session->set($this->entity->getId().'_funnel', $funnelState);
216223
}
217224

218225
private function getEntityName(): string

src/Parthenon/Funnel/FunnelInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,7 @@ public function setSuccessHandler(SuccessHandlerInterface $successHandler): self
3636

3737
public function setSkipHandler(SkipHandlerInterface $skipHandler): self;
3838

39+
public function isLiveEntity(bool $preloaded): self;
40+
3941
public function process(Request $request);
4042
}

0 commit comments

Comments
 (0)