Skip to content

fix(entries): satisfy required slug/date rules from the entry's own values - #40

Merged
sylvesterdamgaard merged 1 commit into
mainfrom
fix/entry-update-slug-validation
Aug 27, 2026
Merged

fix(entries): satisfy required slug/date rules from the entry's own values#40
sylvesterdamgaard merged 1 commit into
mainfrom
fix/entry-update-slug-validation

Conversation

@sylvesterdamgaard

Copy link
Copy Markdown
Contributor

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 is required — Statamic's default — could never be satisfied: every entry update failed with The 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:

  • injects the entry's effective slug (and, on dated collections, its date) back into the validation payload, so blueprint required rules are satisfied from the entry's own values;
  • resolves the UniqueEntryValue({collection}, {id}, {site}) placeholders via withReplacements() on both FieldsValidator invocations (including the TypeError fallback) — the pattern the CP's own EntriesController uses, 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

  • date no 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.
  • Explicit slug on create actually works: createEntry() read $arguments['slug'], but the schema never declared it, so no client could send it. The schema now declares slug, and data.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-based UniqueEntryValue) — 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.

…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
@sylvesterdamgaard
sylvesterdamgaard merged commit 9b2a278 into main Aug 27, 2026
25 of 27 checks passed
@sylvesterdamgaard
sylvesterdamgaard deleted the fix/entry-update-slug-validation branch August 27, 2026 09:11
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.

Regression of #27: entry update now fails with "The Slug field is required"

1 participant