-
Notifications
You must be signed in to change notification settings - Fork 819
Description
Description
The current GridField state management implementation is a bit lacking when dealing with multiple GridFields, especially with the new nested GridField component. It tries to handle GridField states by appending all GridField states as different request variables, and the code that does this is scattered in a few different places.
Our implementation of GridField state management is a GridFieldStateManager class that handles GridField states for all GridFields, not just the current one. The GridFieldStateManager implementation feels like a natural place to handle this, and it should preferably be the only place that handles it.
The way our GridFieldStateManager does this is to store modified GridField states in session, and to append a single request parameter, via the addStateToURL-method, which is already used by all GridFieldStateAware components. This single request parameter simply contains a key, by which the stored GridField states are found from session. In this way it can handle GridField states via session differently per browser tab/window.
With this implementation one could also in the future have different implementations of GridFieldStateManager which store the states somewhere else than session.
The implementation does require some changes to core except the GridFieldStateManager implementation, for example the addAllStateToUrl-method in GridField becomes much simpler.
Additional context or points of discussion
One point to consider here is if the GridFieldStateManager interface needs some new methods. It doesn't currently have any notion of when the GridFieldStateManager implementation should actually store a given GridField state. This means our implementation currently tries to figure this out when some GridFieldStateAware component calls the addStateToURL method, which isn't ideal. It then has to try to figure out if the state has actually changed from the default, and for performance reasons it only checks this once, even if the state might actually be changed later in the request.
Ideally we could add a storeState method to the interface, which could actually be called from the GridState class whenever some of the state data changes (after all GridField_StateProvider components initDefaultState methods have been called).
Notes
- A good place to document how to swap state managers is https://docs.silverstripe.org/en/5/developer_guides/forms/field_types/gridfield/
Acceptance criteria
- A new
SessionGridFieldStateManageris created and stored the GridState in the user's session and targeted at CMS 5. - Ability for content authors to navigate between gridfield search parameters and gridfield record via the browser back/forward buttons is retained.
- The CMS 5 implementation is does not break any API by adding explicit methods to
GridFieldStateManagerInterface. - By default,
GridFieldStateManageris still the default State manager in CMS 5. - CMS 5.3 changelog explains how to opt-in into the new GridState.
Excludes
- Behat test coverage (Will be handled by CMS Squad)