Repository navigation
Conversation
API Platform's documentation recommends a DTO as the resource class. The README only showed the entity as the resource, shaped with serialization groups, so users of the DTO pattern had no guidance. Reads work unchanged there, but the bundle matches submitted translations to their existing rows only when the resource is the entity, so a DTO write needs its own matching by locale. Add a "Using DTO resources" section with two variants: a state provider and processor (every supported API Platform version) and the Symfony Object Mapper (API Platform 4.2 or later). Add a context7 rule for the DTO write path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
API Platform's documentation recommends a DTO as the resource class ("DTO as a Resource"). The README shows only the other setup: the Doctrine entity as the resource, shaped with serialization groups. A user who follows the DTO pattern finds no guidance, and the write path has a trap. The bundle matches submitted translations to their existing rows only when the resource is the entity, so a write through a DTO needs its own matching by locale.
A second trap is the typed
translationsmap of the DTO. Withoutphpstan/phpdoc-parserandphpdocumentor/type-resolver, the entries arrive as plain arrays and the processor fails withAttempt to read property "title" on array.Changes
eager_load_translations, the two translation filters) and what does not apply (thetranslation.groupsfilter and thetranslationsserialization group).getOrCreateTranslation($locale)for each submitted locale, so existing rows are updated in place and keep their ids.PUTis a full replace and needsstandard_putdisabled, as in the setup with serialization groups.PUT, and the section says why.translationsmap needs.