Skip to content

Commit d4086af

Browse files
committed
Add default post type and pattern forms to view config.
Apply a single default form to every post type in `wp_get_entity_view_config()` instead of registering an identical form per type, so `post`, `page`, and custom post types all receive a sensible default. Post types that need a different shape can still replace it entirely through their own `get_entity_view_config_postType_{$post_type}` filter callback. The default is intentionally not gated by `supports`: the registered fields are the single source of truth, and the editor drops any field whose definition is absent or whose `isVisible` returns false. Add a dedicated form for the `wp_block` (pattern) post type, covering excerpt, content info, sync status, and revisions. This ports the changes from the Gutenberg plugin. See WordPress/gutenberg#79625 and WordPress/gutenberg#79452. Follow-up to [62547]. Props jorgefilipecosta, ntsekouras, mcsf. Fixes #65552. git-svn-id: https://develop.svn.wordpress.org/trunk@62588 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 135599d commit d4086af

2 files changed

Lines changed: 107 additions & 144 deletions

File tree

src/wp-includes/default-filters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@
819819
add_filter( 'rest_pre_insert_wp_template_part', 'inject_ignored_hooked_blocks_metadata_attributes' );
820820

821821
// View Config API.
822-
foreach ( array( 'page', 'post', 'wp_block', 'wp_template_part', 'wp_template' ) as $post_type ) {
822+
foreach ( array( 'page', 'wp_block', 'wp_template_part', 'wp_template' ) as $post_type ) {
823823
add_filter(
824824
"get_entity_view_config_postType_{$post_type}",
825825
"_wp_get_entity_view_config_post_type_{$post_type}",

src/wp-includes/view-config.php

Lines changed: 106 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,89 @@
1010
* @since 7.1.0
1111
*/
1212

13+
/**
14+
* Builds the default `form` configuration for post types that don't provide their own.
15+
*
16+
* It is a sensible default for `post`, `page`, and custom post types alike rather
17+
* than being tailored per type. Post types that need a different shape can replace
18+
* it entirely with a dedicated `form` through their own filter callback.
19+
*
20+
* It is intentionally NOT gated by `supports`. The registered fields are the
21+
* single source of truth for what applies: each field is registered for a post
22+
* type based on its `supports` (and related flags such as `theme_supports`), and
23+
* the editor drops any form field whose definition is absent or whose `isVisible`
24+
* returns `false`.
25+
*
26+
* @since 7.1.0
27+
*
28+
* @return array The default form configuration.
29+
*/
30+
function _wp_get_default_post_type_form() {
31+
return array(
32+
'layout' => array( 'type' => 'panel' ),
33+
'fields' => array(
34+
array(
35+
'id' => 'featured_media',
36+
'layout' => array(
37+
'type' => 'regular',
38+
'labelPosition' => 'none',
39+
),
40+
),
41+
array(
42+
'id' => 'post-content-info',
43+
'layout' => array(
44+
'type' => 'regular',
45+
'labelPosition' => 'none',
46+
),
47+
),
48+
array(
49+
'id' => 'excerpt',
50+
'layout' => array(
51+
'type' => 'panel',
52+
'labelPosition' => 'top',
53+
),
54+
),
55+
array(
56+
'id' => 'status',
57+
'label' => __( 'Status' ),
58+
'children' => array(
59+
array(
60+
'id' => 'status',
61+
'layout' => array(
62+
'type' => 'regular',
63+
'labelPosition' => 'none',
64+
),
65+
),
66+
'scheduled_date',
67+
'password',
68+
'sticky',
69+
),
70+
),
71+
'date',
72+
'slug',
73+
'author',
74+
'template',
75+
array(
76+
'id' => 'discussion',
77+
'label' => __( 'Discussion' ),
78+
'children' => array(
79+
array(
80+
'id' => 'comment_status',
81+
'layout' => array(
82+
'type' => 'regular',
83+
'labelPosition' => 'none',
84+
),
85+
),
86+
'ping_status',
87+
),
88+
),
89+
'parent',
90+
'format',
91+
'revisions',
92+
),
93+
);
94+
}
95+
1396
/**
1497
* Returns the view configuration for the given entity.
1598
*
@@ -65,7 +148,7 @@ function wp_get_entity_view_config( $kind, $name ) {
65148
'default_view' => $default_view,
66149
'default_layouts' => $default_layouts,
67150
'view_list' => $view_list,
68-
'form' => array(),
151+
'form' => 'postType' === $kind ? _wp_get_default_post_type_form() : array(),
69152
);
70153

71154
/**
@@ -241,148 +324,6 @@ function _wp_get_entity_view_config_post_type_page( $config ) {
241324
),
242325
);
243326

244-
$config['form'] = array(
245-
'layout' => array( 'type' => 'panel' ),
246-
'fields' => array(
247-
array(
248-
'id' => 'featured_media',
249-
'layout' => array(
250-
'type' => 'regular',
251-
'labelPosition' => 'none',
252-
),
253-
),
254-
array(
255-
'id' => 'post-content-info',
256-
'layout' => array(
257-
'type' => 'regular',
258-
'labelPosition' => 'none',
259-
),
260-
),
261-
array(
262-
'id' => 'excerpt',
263-
'layout' => array(
264-
'type' => 'panel',
265-
'labelPosition' => 'top',
266-
),
267-
),
268-
array(
269-
'id' => 'status',
270-
'label' => __( 'Status' ),
271-
'children' => array(
272-
array(
273-
'id' => 'status',
274-
'layout' => array(
275-
'type' => 'regular',
276-
'labelPosition' => 'none',
277-
),
278-
),
279-
'scheduled_date',
280-
'password',
281-
'sticky',
282-
),
283-
),
284-
'date',
285-
'slug',
286-
'author',
287-
'template',
288-
array(
289-
'id' => 'discussion',
290-
'label' => __( 'Discussion' ),
291-
'children' => array(
292-
array(
293-
'id' => 'comment_status',
294-
'layout' => array(
295-
'type' => 'regular',
296-
'labelPosition' => 'none',
297-
),
298-
),
299-
'ping_status',
300-
),
301-
),
302-
'parent',
303-
'format',
304-
'revisions',
305-
),
306-
);
307-
308-
return $config;
309-
}
310-
311-
/**
312-
* Provides the view configuration for the `post` post type.
313-
*
314-
* @since 7.1.0
315-
*
316-
* @param array $config {
317-
* The view configuration for the entity.
318-
* }
319-
* @return array The filtered view configuration.
320-
*/
321-
function _wp_get_entity_view_config_post_type_post( $config ) {
322-
$config['form'] = array(
323-
'layout' => array( 'type' => 'panel' ),
324-
'fields' => array(
325-
array(
326-
'id' => 'featured_media',
327-
'layout' => array(
328-
'type' => 'regular',
329-
'labelPosition' => 'none',
330-
),
331-
),
332-
array(
333-
'id' => 'post-content-info',
334-
'layout' => array(
335-
'type' => 'regular',
336-
'labelPosition' => 'none',
337-
),
338-
),
339-
array(
340-
'id' => 'excerpt',
341-
'layout' => array(
342-
'type' => 'panel',
343-
'labelPosition' => 'top',
344-
),
345-
),
346-
array(
347-
'id' => 'status',
348-
'label' => __( 'Status' ),
349-
'children' => array(
350-
array(
351-
'id' => 'status',
352-
'layout' => array(
353-
'type' => 'regular',
354-
'labelPosition' => 'none',
355-
),
356-
),
357-
'scheduled_date',
358-
'password',
359-
'sticky',
360-
),
361-
),
362-
'date',
363-
'slug',
364-
'author',
365-
'template',
366-
array(
367-
'id' => 'discussion',
368-
'label' => __( 'Discussion' ),
369-
'children' => array(
370-
array(
371-
'id' => 'comment_status',
372-
'layout' => array(
373-
'type' => 'regular',
374-
'labelPosition' => 'none',
375-
),
376-
),
377-
'ping_status',
378-
),
379-
),
380-
'parent',
381-
'format',
382-
'revisions',
383-
),
384-
);
385-
386327
return $config;
387328
}
388329

@@ -473,6 +414,28 @@ function _wp_get_entity_view_config_post_type_wp_block( $config ) {
473414

474415
$config['view_list'] = $view_list;
475416

417+
$config['form'] = array(
418+
'layout' => array( 'type' => 'panel' ),
419+
'fields' => array(
420+
array(
421+
'id' => 'excerpt',
422+
'layout' => array(
423+
'type' => 'panel',
424+
'labelPosition' => 'top',
425+
),
426+
),
427+
array(
428+
'id' => 'post-content-info',
429+
'layout' => array(
430+
'type' => 'regular',
431+
'labelPosition' => 'none',
432+
),
433+
),
434+
'sync-status',
435+
'revisions',
436+
),
437+
);
438+
476439
return $config;
477440
}
478441

0 commit comments

Comments
 (0)