Skip to content

Conversation

VincentLanglet
Copy link
Contributor

@VincentLanglet VincentLanglet commented Oct 1, 2025

Q A
Branch? main
Tickets Closes #..., closes #...
License MIT
Doc PR api-platform/docs#...

When writing a route with a custom input like

new Patch(
      uriTemplate: '/users/{uuid}/verify',
      input: UserVerifyInput::class,
      processor: UserProcessor::class,
),

with an input like

class UserVerifyInput { public string $code; }

I didn't find an easy way to access to the User resource (in order to modify it), resolved by the URL.
The $context['previous_data'] doesn't fulfill this job because it's a cloned data so if we try to modify/flush the data it does nothing and if we try to modify/persist/flush the data we get an EntityCollision error with doctrine.

The data request attribute coming from the ReadProvider is later overridden by the DeserializeListener which are generating the Input. Too bad API platform doesn't keep a reference to this resource somewhere no ?
I would save an extra query in the processor

$entityManager->find($context['previous_data']->getId());

So what about adding a resource key in the request/context ?
When trying locally it works for me with the ReadProvider + WriteListener changes, but I dunno if

  • I should update ApiPlatformController too ?
  • I should update ObjectMapperProvider too ?
  • There is another place to update.

Also, you might want to challenge the naming.

@VincentLanglet VincentLanglet marked this pull request as draft October 1, 2025 08:52
@VincentLanglet
Copy link
Contributor Author

Seems like my issue is related to use_symfony_listeners: true.

Without, the context has a data key witch map to the resource (which is also in the request)
With, the context has lost this key.

@VincentLanglet
Copy link
Contributor Author

Let's start with an issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant