Skip to content

Commit 97ce759

Browse files
committed
fix(state): map previous_data to the stateOptions class
The Doctrine PersistProcessor standard PUT reads previous_data as the entity, but ObjectMapperProvider stores the API resource there. Fixes #8866
1 parent 168f17e commit 97ce759

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎src/State/Processor/ObjectMapperInputProcessor.php‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,15 @@ public function process(mixed $data, Operation $operation, array $uriVariables =
5454
}
5555

5656
$request = $context['request'] ?? null;
57-
$mapped = $this->objectMapper->map($data, $request?->attributes->get('mapped_data') ?? $this->getStateOptionsClass($operation, $operation->getClass()));
57+
$targetClass = $this->getStateOptionsClass($operation, $operation->getClass());
58+
$mapped = $this->objectMapper->map($data, $request?->attributes->get('mapped_data') ?? $targetClass);
5859
$request?->attributes->set('mapped_data', $mapped);
5960

61+
$previousData = $context['previous_data'] ?? null;
62+
if (\is_object($previousData) && null !== $targetClass && !$previousData instanceof $targetClass) {
63+
$context['previous_data'] = $this->objectMapper->map($previousData, $targetClass);
64+
}
65+
6066
return $this->decorated ? $this->decorated->process($mapped, $operation, $uriVariables, $context) : $mapped;
6167
}
6268
}

0 commit comments

Comments
 (0)