getgrav / getgrav/grav-plugin-admin
Expose a public API to mark a form clean after plugin-controlled save-like actions
- Dominant language
- PHP
- Stars
- 377
- Forks
- 225
- Avg merge
- 11h 51m
- Merged PRs (30d)
- 4
Description
Grav Admin currently works very well for the classic flow:
- user edits a form
- form becomes dirty
- user clicks `Save`
- page reloads
- Admin considers the form clean again
However, this becomes difficult for plugins that add more advanced behavior on top of the existing Admin form model.
## Problem
Some plugins need to support save-like flows that still stay compatible with normal Grav forms, for example:
- deferred actions prepared in the form and applied on `Save`
- plugin-controlled AJAX save helpers
- post-save UI/state refresh without relying only on a full page reload
- custom save flows around plugin config and Flex config
In these cases, plugins currently do not have a supported/public way to tell Admin:
- this form is now clean
- the unsaved-changes state should be reset
- the `Changes Detected` modal should not remain or reopen
- `#changes` should not survive once the form is no longer dirty
Today, plugin authors end up depending on internal implementation details such as:
- `Grav.default.Forms.FormState`
- remodal internals
- URL hash cleanup for `#changes`
That works as a local workaround, but it is brittle and tightly coupled to Admin internals.
## Why this matters
The issue is not that plugins want to replace Grav’s normal `Save` flow.
The issue is that plugins sometimes need to extend it in a way that is still conceptually “a successful save”, but Admin has no official extensibility point for resetting its dirty-state and modal state.
This can lead to UX problems such as:
- `Changes Detected` appearing after a successful save
- `#changes` remaining in the URL and reopening the modal on reload
- plugins having to implement their own cleanup logic around Admin internals
Similar dirty-state / `Changes Detected` problems have surfaced before in issues such as:
- [#823](https://github.com/getgrav/grav-plugin-admin/issues/823)
- [#1091](https://github.com/getgrav/grav-plugin-admin/issues/1091)
## Proposal
Expose a small public Admin-side API for form state management.
For example, something along these lines:
- `GravAdmin.Forms.isDirty(formId)`
- `GravAdmin.Forms.markClean(formId)`
- `GravAdmin.Modals.closeChanges()`
Or a single higher-level helper such as:
- `GravAdmin.afterSuccessfulSave(formId)`
At minimum, the API should allow plugins to do the equivalent of:
1. rebaseline the form
2. mark it as clean
3. close the unsaved-changes modal if open
4. clear `#changes` if the form is no longer dirty
## Compatibility
This proposal is intentionally small and backward-compatible.
It does **not** ask for:
- a rewritten Admin frontend
- a new reactive framework
- replacing the existing full-page save model
- changing old plugin behavior
Existing plugins would continue to work as before.
This would only provide a supported integration point for plugins that need to extend Admin behavior without poking internal state objects and remodal/hash details.
## Expected benefit
A public clean/rebaseline API would make advanced Admin integrations much safer and less hacky, especially for:
- plugin config screens
- Flex-based admin forms
- save-like custom actions
- progressive enhancement of existing forms
Right now the only option is to patch around Admin internals. A supported API here would significantly improve plugin extensibility without requiring a breaking redesign of Admin.
Contributor guide
Assessment
This issue has not been assessed yet.