Skip to content

Commit fddfe5b

Browse files
committed
Fix form submit endpoint to always return Form entity, not success handler result
The submit endpoint was replacing its Form response with the success handler's result (e.g. the created User on registration). This produced inconsistent @type/@id when the form handler returned a non-Form entity. Now only Response objects (e.g. 404 from PasswordUpdateListener) replace the Form result — entity results are side-effects and the Form is always returned. Registration test updated to validate the Form schema instead of expecting a User entity in the response.
1 parent 994f393 commit fddfe5b

2 files changed

Lines changed: 6 additions & 17 deletions

File tree

features/user/register_form.feature

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,7 @@ Feature: Register process via a form
2727
And the response status code should be 201
2828
And the response should be in JSON
2929
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
30-
And the JSON should be a superset of:
31-
"""
32-
{
33-
"@context": "/contexts/User",
34-
"@type": "User",
35-
"username": "new_user",
36-
"emailAddress": "user@example.com",
37-
"_metadata": {
38-
"persisted": true
39-
}
40-
}
41-
"""
42-
And the JSON should be valid according to the schema file "user.schema.json"
30+
And the JSON should be valid according to the schema file "form.schema.json"
4331
And I should get a "user_welcome" email sent
4432

4533
Scenario Outline: Submit a duplicate user registration form

src/EventListener/Api/FormApiEventListener.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ private function handleFormData(ViewEvent $event): void
6868

6969
if ($data->formView->getForm()->isValid()) {
7070
$result = $this->formSubmitHelper->handleSuccess($data);
71-
if ($result) {
72-
// we were going to do sub-requests, but then we may require authorization and for forms we shouldn't need that
73-
// instead Form:component:read serialization group should be added to properties of objects being returned
74-
// for them to be serialized in the result
71+
// Only replace the Form with the result if it is an explicit Response object
72+
// (e.g. a 404 from PasswordUpdateListener). Entity results (e.g. the created User
73+
// from registration) are intentionally ignored — the submit endpoint always returns
74+
// the Form entity so @type and @id remain stable regardless of side-effects.
75+
if ($result instanceof Response) {
7576
$data = $result;
7677
}
7778
}

0 commit comments

Comments
 (0)