Skip to content

Commit

Permalink
Dont keep data when invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
barryvdh committed Oct 7, 2019
1 parent 689a2a1 commit 1caa06e
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/Extension/Session/SessionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ public function preSet(FormEvent $event)
if (! is_null($oldValue)) {

// Transform back to good data
$value = $this->transformValue($event, $oldValue);

// Store on the form
$event->setData($value);
try {
$value = $this->transformValue($event, $oldValue);

// Store on the form
$event->setData($value);
} catch (TransformationFailedException $e) {
// Cannot transform the data
}
}

if ($errors = session('errors')) {
Expand Down Expand Up @@ -100,20 +105,12 @@ protected function transformValue(FormEvent $event, $value)

// Reverse them all..
foreach ($config->getViewTransformers() as $transformer) {
try {
$value = $transformer->reverseTransform($value);
} catch (TransformationFailedException $e) {
//
}
$value = $transformer->reverseTransform($value);
}

// Map the models to correct values
foreach ($config->getModelTransformers() as $transformer) {
try {
$value = $transformer->reverseTransform($value);
} catch (TransformationFailedException $e) {
//
}
$value = $transformer->reverseTransform($value);
}

return $value;
Expand Down

0 comments on commit 1caa06e

Please sign in to comment.