View config schema: centralize in PHP - #81169
Conversation
Adds property descriptions to the view config REST controller schema, a PHP dump script that extracts the schema without a WordPress runtime, and a docs generator (npm run docs:view-config-ref) that fills the property tables in view-config-reference.md between autogenerated tokens. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Moves the REST controller's item schema into lib/compat/wordpress-7.1/view-config-schema.php, consumed independently by the controller (require + memoize) and by the docs dump script, which no longer needs to stub WP_REST_Controller or load the controller class. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Size Change: 0 B Total Size: 7.81 MB |
| | Property | Description | Type | | ||
| | -------- | ----------- | ---- | | ||
| | layout | The default layout for the form fields. | `{ type: regular \| panel \| card \| row \| details, … }` | | ||
| | fields | The fields of the form, in display order. Each entry is a field id, or an object for further configuration. | `[ string \| { id, label, description, layout, children } ]` | |
There was a problem hiding this comment.
Vertical pipe char inside code tag is being escaped:
-| `[ string \| { id, label, description
+| `[ string | { id, label, description| if ( ! function_exists( '__' ) ) { | ||
| /** | ||
| * Stub for the WordPress translation function: returns the text untranslated. | ||
| * | ||
| * @param string $text Text to translate. | ||
| * @param string $domain Text domain (unused). | ||
| * @return string The original text. | ||
| */ | ||
| function __( $text, $domain = 'default' ) { | ||
| return $text; | ||
| } | ||
| } |
There was a problem hiding this comment.
The requisite here is that the PHP schema file remains as WordPress agnostic as possible. The __ function is used by it so property descriptions are picked up for translation, so we need to stub it. This requisite seems a bit fragile and disconnected (someone adding other functions in the file may discover this connection only when the build docs process fails).
| async function main() { | ||
| let stdout; | ||
| try { | ||
| ( { stdout } = await execa( 'php', [ DUMP_SCRIPT_PATH ] ) ); |
There was a problem hiding this comment.
This script requires the PHP binary on path to extract the schema (see dump-view-config-schema.php.
|
I'm favoring #81168 over this one. |
It's not a strong opinion, but I agree with your take! |
Alternative to #81168
What?
This PR centralizes the schema for the view config API into PHP. Then, everything is derived from it (docs, schema/json).
Why?
To have a single place to define the schema.
How?
schemas/jsonfrom the PHP schema.Testing Instructions
TBD