Replies: 1 comment
-
|
Hey! You can do this by setting |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
content:beforeSavecan mutate a content record but cannot reject the save. Today the only way to stop bad content from being saved is to throw frombeforeSave, which surfaces to the admin UI as an opaque server error rather than a structured, field-scoped validation message.Concrete motivator: an SEO plugin wants to enforce:
<h1>per posttitleanddescriptionacross published contentThese are validation, not mutation. Failing a save from
beforeSaveloses the structured "field X failed because Y" information the admin UI needs.Proposed hook
New hook
content:validate. Dedicated validation phase. Runs afterbeforeSavemutations and before the DB write. Multiple plugins can register; pipeline collects all errors from all plugins (so the author sees every issue at once, not one-at-a-time whack-a-mole).Dispatch semantics:
error-severity result, the save is rejected.API surface to the admin
Save API response on validation failure:
{ "ok": false, "error": "validation", "validation": [ { "field": "title", "code": "seo.duplicate_title", "message": "Another post already uses this title.", "severity": "error", "source": "emdash-plugin-seo" } ] }sourceis added by core (plugin id of the handler that produced the error) — plugins don't need to set it themselves.HTTP status:
422 Unprocessable Entity.Integration site
In the save pipeline (wherever
content:beforeSaveis dispatched today). After that dispatch and beforerepo.save(), call the newcontent:validatedispatcher; if it returns anyerror-severity items, short-circuit with a 422 and the structured payload.Autosave should skip
content:validate— drafts are allowed to be invalid. Publish transitions run it.Open questions
status === "published"record; skip for drafts. Plugins that want draft-time validation can gate onevent.content.statusthemselves.ctx.content.list()/ctx.dband cache. Optimization later.?skipValidation=truefor trusted tooling? Proposal: same pipeline, no skip — if trusted tooling needs to bypass, it should use an internal flag that's not URL-exposed.References
content:beforeSave(packages/core/src/plugins/types.ts—ContentBeforeSaveHandler)packages/core/src/plugins/hooks.tsNeeded for
emdash-plugin-seobuild-time / pre-publish validation. Happy to implement once shape + dispatch semantics are approved.Beta Was this translation helpful? Give feedback.
All reactions