Skip to content

docs(readme): document DTO resources - #96

Closed
paullla wants to merge 1 commit into
Locastic:masterfrom
paullla:docs/dto-recipe
Closed

paullla wants to merge 1 commit into
Locastic:masterfrom
paullla:docs/dto-recipe

Conversation

@paullla

@paullla paullla commented Nov 19, 2026

Copy link
Copy Markdown
Member
Q A
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Issues -
License MIT

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 translations map of the DTO. Without phpstan/phpdoc-parser and phpdocumentor/type-resolver, the entries arrive as plain arrays and the processor fails with Attempt to read property "title" on array.

Changes

  • New README section "Using DTO resources". It says what works unchanged with a DTO (locale resolution, the fallback locale, eager_load_translations, the two translation filters) and what does not apply (the translation.groups filter and the translations serialization group).
  • First variant: a state provider and processor, for every supported API Platform version. The processor calls getOrCreateTranslation($locale) for each submitted locale, so existing rows are updated in place and keep their ids. PUT is a full replace and needs standard_put disabled, as in the setup with serialization groups.
  • Second variant: the Symfony Object Mapper, for API Platform 4.2 or later. It has no provider and no processor. One transformer matches the translations by locale. This variant has no PUT, and the section says why.
  • A note on the two packages that the typed translations map needs.
  • One new context7 rule for the write path with a DTO.
  • No code changes.

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.
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