fix(entries): satisfy required slug/date rules from the entry's own values - #40
Merged
Merged
Conversation
…alues The #27 fix removed the slug from the validated payload before blueprint validation, so a blueprint whose slug field is required — Statamic's default — could never be satisfied: every update failed with "The Slug field is required" no matter what the caller sent (#39). Slug and date are entry properties, not data keys, so the merged payload never contains them on its own. Inject the entry's effective values into the validation payload and resolve the UniqueEntryValue({collection}, {id}, {site}) placeholders via withReplacements() on both FieldsValidator invocations (including the TypeError fallback), matching how the CP's EntriesController validates. With the entry's own id excluded, the re-validated slug cannot trip the uniqueness rule — the false positive that #27 was about — while a slug owned by another entry is still rejected. Also from the #39 report: - date no longer has to be resent on every update of a dated collection; the entry's current date satisfies a required rule when omitted - create's slug argument is now declared in the tool schema (it was read but impossible to send), and data.slug is accepted as an alias Fixes #39
3 tasks
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.
Fixes #39.
The bug
The #27 fix removed the slug from the validated payload before blueprint validation (
unset($data['slug'])). That resolved the "already been taken" false positive, but a blueprint whose slug field isrequired— Statamic's default — could never be satisfied: every entry update failed withThe Slug field is required, whether the caller omitted the slug or resent the current one.The fix
Slug and date are entry properties, not data keys, so the merged validation payload never contains them on its own. The update flow now:
requiredrules are satisfied from the entry's own values;UniqueEntryValue({collection}, {id}, {site})placeholders viawithReplacements()on bothFieldsValidatorinvocations (including theTypeErrorfallback) — the pattern the CP's ownEntriesControlleruses, and the fix originally recommended in Update action fails with "slug: This value has already been taken" for existing entries #27. With the entry's id excluded, re-validating the current slug cannot trip the uniqueness rule, while a slug owned by another entry is still rejected (covered by test).The dedicated pre-check from #27 stays: it still gives a precise
Slug validation failed: …message on genuine collisions.Also from the #39 report
dateno longer has to be resent on every update of a dated collection; the entry's current date satisfies a required rule when the payload omits it.createEntry()read$arguments['slug'], but the schema never declared it, so no client could send it. The schema now declaresslug, anddata.slug(the shape update uses) is accepted as an alias — stored as an entry property in both cases, never as a data key.Tests
7 new regression tests use the real Statamic default blueprint (
slug: required+ placeholder-basedUniqueEntryValue) — the setup the existing #27 tests lacked, which is why they missed this. Verified the new tests fail against the previous code (3 red) and pass with the fix.Full gate is green: Pint, PHPStan level 9 (no ignores), 1100 tests, license check, SBOM drift check,
composer audit.