#66229 closed enhancement (fixed)
Register and filter fields for DataViews/DataForm in the server
| Reported by: | oandregal | Owned by: | oandregal |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.2 |
| Component: | General | Version: | trunk |
| Severity: | normal | Keywords: | has-patch has-unit-tests gutenberg-merge |
| Cc: | Focuses: |
Description
Related to https://core.trac.wordpress.org/ticket/65981
We want to introduce the ability to register and extend the fields used by DataViews/DataForm in the server for any given entity.
The whole initiative is tracked in Gutenberg at https://github.com/WordPress/gutenberg/issues/74865
Change History (20)
This ticket was mentioned in PR #13911 on WordPress/wordpress-develop by @oandregal.
6 weeks ago
#2
- Keywords has-patch has-unit-tests added
#3
@
6 weeks ago
Tested PR #13911 on WordPress Playground (core-pr=13911).
Environment:
- WordPress: 7.2-alpha-20261001.231912
- PHP: 7.4
- Playground (WASM) — https://playground.wordpress.net/?core-pr=13911
Testing performed:
- REST endpoint verification
- GET /wp/v2/fields → 400 rest_missing_callback_param (kind, name required) ✅
- GET /wp/v2/fields?kind=postType&name=page (unauthenticated) → 401 rest_cannot_read ✅
- GET /wp/v2/fields?kind=postType&name=page (authenticated via wp.apiFetch) → 200 with empty fields ✅
- Field registration via fields_api_init hook
Registered 2 custom fields on postType/page using WP_Fields_Registry::register():
- my_test_field (text)
- my_second_field (integer)
Confirmed signature: register( $origin, $kind, $name, $fields[], $script_module = null )
- REST response after registration GET /wp/v2/fields?kind=postType&name=page → { kind: 'postType', name: 'page', fields: Array(2), script_modules: Array(0) } Both fields returned correctly ✅
- Validation
- Calling register() with incorrect arguments (missing 'id' in field definition) produces proper _doing_it_wrong() notice ✅
- Duplicate fields are skipped as documented ✅
Result: PR works as described. The register() method correctly stores origin as
both 'origin' and 'registeredBy' properties on each field, and the REST
controller serves them per entity.
Note: During testing, I confirmed that the fields definition parameter must be
a list of arrays (each with an 'id' key), not a single field definition. The
docblock is clear about this, but it's worth noting for anyone writing their
first registration.
Props to @oandregal for the implementation.
#5
@
4 weeks ago
I’m going through the 7.2 tickets ahead of beta 1.
Thank you for the update, @oandregal. Are we targeting 7.2 for this? If it needs more time, we can move it to 7.3.
#6
@
4 weeks ago
@im3dabasia1 We're polishing some details over at Gutenberg and aim to get this merged for 7.2.
@oandregal commented on PR #13911:
3 weeks ago
#8
https://github.com/WordPress/wordpress-develop/pull/14495 was merged and this rebased onto trunk.
@oandregal commented on PR #13911:
3 weeks ago
#9
Committed at https://core.trac.wordpress.org/changeset/64528
This ticket was mentioned in PR #14512 on WordPress/wordpress-develop by @jorgefilipecosta.
3 weeks ago
#10
Backports the PHP of https://github.com/WordPress/gutenberg/pull/84696, a follow-up to the entity fields API that landed in r64528.
Gutenberg registers the core fields (title, author, status, the media fields…) on the server, through the entity fields API, and the editors read them from /wp/v2/entity-fields. Core has the API but registers no fields yet, so the title column of the site editor's pages list is blank. This PR makes Core register them.
This PR:
- Copies the PHP files of
@wordpress/core-fieldsfrom the Gutenberg build towp-includes/build/scripts/core-fields/, in thegutenberg-phpcopy task that copiesroutes.phpandpages.php, and loads itsindex.phpfromwp-settings.phpthe same way. - Makes the existing entity fields tests replace the core fields with their fixture defaults, so they keep testing the API alone.
- Ports the tests of
wp_register_core_field_collections()andwp_register_core_post_type_supports_fields().
Some notes:
- This needs a Gutenberg pin that includes https://github.com/WordPress/gutenberg/pull/84696, which comes in its own PR along with the files it generates. Until then
wp-includes/build/scripts/core-fields/doesn't exist, so the new tests fail. - The pin also needs https://github.com/WordPress/gutenberg/pull/85139, which removes the
gutenbergtext domain from the labels, so they are translated with the default one. Thetest_the_labels_are_translated_with_the_default_text_domaintest covers it. - It touches the same lines of
Gruntfile.jsandwp-settings.phpas https://github.com/WordPress/wordpress-develop/pull/14509, which does the same for the core actions; whichever lands second needs a trivial rebase.
Testing Instructions
- Set
gutenberg.shainpackage.jsontotrunk, then runnpm run gutenberg:downloadandnpm run build:dev. - Open
wp-admin/site-editor.php?p=%2Fpageand verify the pages list shows the titles, authors, and statuses of the pages. - In the console, run
await wp.apiFetch( { path: '/wp/v2/entity-fields?kind=postType&name=page' } )and verify it returns the fields of pages with the@wordpress/core-fields/post_type_supportsand@wordpress/core-fields/pagemodules. - Open the templates, patterns, and media screens of the site editor and verify their fields, and the site identity screen with the site title, tagline, logo, and icon.
- Run
npm run test:php -- --group entity-fields.
Gutenberg PR: https://github.com/WordPress/gutenberg/pull/84696
Use of AI Tools
AI assistance: Yes
Used for: porting the code and the tests from the Gutenberg PR, and drafting this description; reviewed and edited by me.
This ticket was mentioned in PR #14513 on WordPress/wordpress-develop by @jorgefilipecosta.
3 weeks ago
#11
Backports the view config changes of https://github.com/WordPress/gutenberg/pull/84700 into the core.
This PR adds the view configs that core was still missing:
attachment: the media editor form (title, alt text, caption and description, then date, author, filename, MIME type, file size, dimensions and "Attached to"). Without it, the media editor modal falls back to the default post type form and its "Details" tab shows only "Date added" and "Author".wp_navigation: a list view sorted by date, newest first.
The root/site form, the wp_template reading_settings field and the group summaries of the default post type form are already in core.
Testing
Verify unit tests are passing:
vendor/bin/phpunit --group view-config
With https://github.com/WordPress/wordpress-develop/pull/14512 applied, open the "Edit image" modal from the Image block toolbar and check that the "Details" tab shows the attachment fields.
Drafted with AI assistance (Claude Code) and reviewed by me.
🤖 Generated with Claude Code
@oandregal commented on PR #14512:
3 weeks ago
#12
I've tested this as part of https://github.com/WordPress/wordpress-develop/pull/14514
@jorgefilipecosta commented on PR #14513:
3 weeks ago
#14
This ticket was mentioned in PR #14716 on WordPress/wordpress-develop by @oandregal.
3 weeks ago
#16
Follow-up to the Entity Actions and Entity Fields APIs.
Bug fixes
_wp_preload_entity_actions()and_wp_preload_entity_fields()assumed$pathswas an array. If an earlierblock_editor_rest_api_preload_pathscallback returnednull,false,'', a string or an object, the editor crashed. Empty values now become an array so the entity paths are still added. Other non-array values, or a context that isn't aWP_Block_Editor_Context, are returned unchanged.$contextnow defaults tonull, so a call with one argument no longer throws anArgumentCountError.WP_Entity_Fields_Registry::get_all_registered_field_modules()returned numeric module ids as integers (from the array keys). They're now cast to strings, matching the actions registry, so the editor script declares the id as it was registered.
Code cleanup
The actions and fields code was duplicated. It now shares two helpers in a new entity-utils.php, loaded before both APIs:
_wp_add_entity_preload_paths( $paths, $context, $route ): used by both preload callbacks. The single-use helpers_wp_get_post_type_fields_preload_paths()and_wp_get_site_editor_screen_post_types()are inlined into it._wp_add_entity_modules_to_editor_script( $scripts, $get_modules ): used by bothadmin_footercallbacks. It takes a callable, not the modules, so the registry is still only read (and its init action only fired) on pages that load the editor script.
No behavior changes beyond the two fixes.
Testing
npm run test:php -- --group entity-actions,entity-fields
A new test covers numeric module ids. The unregistered post types test now goes through _wp_preload_entity_fields().
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Implementation, tests, and this summary; reviewed by me.
@oandregal commented on PR #14716:
3 weeks ago
#18
Committed at https://core.trac.wordpress.org/changeset/64686
@Joen commented on PR #14716:
3 weeks ago
#19
Noting that I'm seeing some errors that I think are caused by this PR, with context here.
@oandregal commented on PR #14716:
3 weeks ago
#20
Thanks for the heads-up, I've just merged https://github.com/WordPress/gutenberg/pull/85390 that should fix them. I didn't expect Gutenberg's CI to pick the last WordPress version so fast! Should I know, I'd have synced the merging of both PRs. Sorry for the inconvenience.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Trac ticket: https://core.trac.wordpress.org/ticket/66229
See: https://github.com/WordPress/gutenberg/pull/83368
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Opus 5.5
Used for: Implementation. Reviewed and edited by me.