View Config: Add version handling#12391
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Hi there! 👋 Thank you for your contribution to WordPress! 💖 It looks like this is your first pull request to No one monitors this repository for new pull requests. Pull requests must be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. Pull requests are never merged on GitHub. The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making. More information about how GitHub pull requests can be used to contribute to WordPress can be found in the Core Handbook. Please include automated tests. Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the Automated Testing page in the handbook. If you have not had a chance, please review the Contribute with Code page in the WordPress Core Handbook. The Developer Hub also documents the various coding standards that are followed:
Thank you, |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
e76839d to
5c779ec
Compare
mcsf
left a comment
There was a problem hiding this comment.
This looks pretty good! I left a couple of recommendations.
5c779ec to
9b18f0e
Compare
Backport the GB PR: WordPress/gutenberg#79809
Trac ticket: https://core.trac.wordpress.org/ticket/65577
What?
Adds version handling to the server-side view configuration API (
wp_get_entity_view_config()).Why?
Right now consumers of the filters have to customize the config by walking the raw payload (find the right index,
foreach,unset, etc.), and imperative array manipulation can never be migrated. A later shape change could break existing callbacks in the wild. So even though there is only version1today and no migrations exist, this code is the safeguard to keep filters working in a possible shape change.How?
The approach here partially mirrors
theme.jsonversion handling, where documents declare aversionandWP_Theme_JSON_Data->update_with()migrates older data forward. So instead of mutating a single payload directly, now callbacks receive a data container (WP_View_Config_Data) and update the config through the container's specific methods.Any update made is marked against the version it was written, and the payload could be migrated in newer versions.
Where it differs from
theme.jsonhandling is the need for updating configs that are arrays (e.g.fieldsandview_list) and handling index based transforms cannot happen reliably in a filter. These props though have stable identities (field.id,view_list.slug), so each part of the config has its own update function and patches are keyed by that identity: the key names the member, the value carries only the changes. All the update functions follow the same rules — an associative array merges key by key, a numerically indexed array replaces wholesale, andnulldeletes what it names: a nested key, a whole member, or a whole top-level key (which resets it to its default).update_properties()update_properties( $patch, $version )merges partial changes intodefault_view,default_layouts, andformexcept itsfields.nullpatch value unsets a nested key, andnullfor a whole top-level key resets it to its default.update_view_list_items()update_view_list_items( $items, $version )patches theview_list, keyed byslug.nullremoves the view.update_form_fields()update_form_fields( $fields, $version )patches theformfields, keyed byid. A field is found wherever it lives — at the top level or nested inside a group'schildren— so a patch only needs the id.nullremoves the field.'my_field' => array(). Inside a field patch, an associativechildrenvalue merges into the group's children byid(unknown ids append to the group), while a numerically indexed one replaces them wholesale.set()Replaces a whole top-level key. It shouldn't be the default choice — a callback using it stops inheriting core's future changes to that key — but it's useful for cases like a CPT that doesn't want the default post form at all.
Testing Instructions
The editor changes consuming the versioned endpoint live in the Gutenberg packages, so testing here is against the API and REST endpoint directly.
versionis1.view_list: the "My drafts" view is appended, the Drafts view is retitled "In progress" (its filters untouched), and the Trash view is gone.form.fields:slugandauthorare gone, and thediscussiongroup'schildrenincludemy_field.default_layoutsno longer has agridkey.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 4.8, Claude Fable 5
Used for: Porting the merged Gutenberg PR to core with direction, changes and review by me.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.