Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backport-changelog/7.2/13308.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/13308

* https://github.com/WordPress/gutenberg/pull/82175
72 changes: 72 additions & 0 deletions lib/compat/wordpress-7.2/view-config-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,78 @@ function _gutenberg_get_entity_view_config_posttype_wp_navigation( $data ) {
return $data;
}

/**
* Post types whose base definition provides its own `form`, without the
* `status` and `discussion` groups of the default post type form.
*
* @var string[]
*/
const GUTENBERG_VIEW_CONFIG_POST_TYPES_WITH_OWN_FORM = array( 'wp_block', 'wp_template', 'wp_template_part' );

/**
* Makes the panel summary of the `status` and `discussion` groups explicit in
* the default post type form.
*
* Both groups used to be summarized by the field sharing their id (`status`,
* and the composite `discussion` field). A combined form field no longer
* resolves its own id against the field definitions, so the summary field is
* declared through `layout.summary` instead. The patch merges into the existing
* group members by id, leaving the rest of the form untouched.
*
* @param Gutenberg_View_Config_Data $data The view configuration container for the entity.
* @return Gutenberg_View_Config_Data The updated view configuration container.
*/
function _gutenberg_add_group_summaries_to_default_posttype_form( $data ) {
return $data->merge(
array(
'form' => array(
'fields' => array(
array(
'id' => 'status',
'layout' => array(

@oandregal oandregal Aug 28, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This merge operation only adds the layout (with the summary) to the respective fields (status and discussion) but leaves the rest as it was in the 7.1 folder (children).

'type' => 'panel',
'summary' => 'status',
),
),
array(
'id' => 'discussion',
'layout' => array(
'type' => 'panel',
'summary' => 'discussion',
),
),
),
),
),
1
);
}

/**
* Layers the group summaries on top of the view configuration of every post
* type that uses the default form, including custom post types registered at
* any point.
*
* The callback merges by member id, and a member that is absent would be
* appended instead, so post types whose base definition provides its own form
* are skipped.
*
* @param string $post_type The post type being registered.
*/
function gutenberg_register_default_posttype_form_summaries_7_2( $post_type ) {
if ( in_array( $post_type, GUTENBERG_VIEW_CONFIG_POST_TYPES_WITH_OWN_FORM, true ) ) {
return;
}

add_filter(
gutenberg_get_entity_view_config_hook_name( 'postType', $post_type ),
'_gutenberg_add_group_summaries_to_default_posttype_form',
6,
1
);
}
add_action( 'registered_post_type', 'gutenberg_register_default_posttype_form_summaries_7_2' );

/**
* Registers the entity view configuration filters that layer on top of the base
* definitions, at a priority between those (5) and third-party callbacks (10),
Expand Down
31 changes: 31 additions & 0 deletions packages/dataviews/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,37 @@

## Unreleased

### Breaking Changes

@oandregal oandregal Aug 28, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've searched across a few repos I regularly work with that are consumers of this library (automattic/wp-calypso, woocommerce, jetpack) and found no affected cases. Even though I'd consider this a bug, I want to treat it as a breaking change to give consumers a heads-up and an example to migrate to the proper API, should there be anyone affected.


- DataForm: a combined form field (one with `children`) is now treated purely as a layout container. Its `id` is no longer resolved against the field definitions: a field sharing that `id` no longer contributes validation rules to the group, and the `panel` layout no longer uses it for the collapsed summary or `readOnly` state, falling back to the group's first leaf child instead ([#82175](https://github.com/WordPress/gutenberg/pull/82175)).

If a combined field relied on sharing its `id` with a field to pick the panel summary, declare it through `layout.summary` instead. For example, a `discussion` field whose `render` summarizes `comment_status` and `ping_status` together:

```js
// Before: the summary came from the `discussion` field because the group shares its id.
const form = {
layout: { type: 'panel' },
fields: [
{ id: 'discussion', children: [ 'comment_status', 'ping_status' ] },
],
};

// After: the summary field is explicit. Without it, the group would
// now be summarized by its first child, `comment_status`.
const form = {
layout: { type: 'panel' },
fields: [
{
id: 'discussion',
layout: { type: 'panel', summary: 'discussion' },
children: [ 'comment_status', 'ping_status' ],
},
],
};
```

If a combined field relied on a same-id field's `isValid` rules being applied to the group, move those rules to the child fields.

### Internal

- Remove unused dependency `@wordpress/primitives` ([#82103](https://github.com/WordPress/gutenberg/pull/82103)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,34 @@ const getFieldDefinition = < Item >(
field: NormalizedFormField,
fields: NormalizedField< Item >[]
) => {
const fieldDefinition = fields.find( ( _field ) => _field.id === field.id );
// A combined form field is a layout container, not a field: its id is
// never resolved against the field definitions. Fall back to its first
// leaf child so the panel has a definition for the summary and
// `readOnly` state.
if ( !! field.children ) {
const simpleChildren = field.children.filter(
( child ) => ! child.children
);

if ( ! fieldDefinition ) {
return fields.find( ( _field ) => {
if ( !! field.children ) {
const simpleChildren = field.children.filter(
( child ) => ! child.children
);
if ( simpleChildren.length === 0 ) {
return undefined;
}

if ( simpleChildren.length === 0 ) {
return false;
}

return _field.id === simpleChildren[ 0 ].id;
}

return _field.id === field.id;
} );
return fields.find(
( _field ) => _field.id === simpleChildren[ 0 ].id
);
}

return fieldDefinition;
return fields.find( ( _field ) => _field.id === field.id );
};

/**
* Determines the field definition and summary fields for a panel layout.
*
* Summary fields are determined with the following priority:
* 1. Use layout.summary fields if they exist
* 2. Fall back to the field definition that matches the form field's id
* 3. If the form field id doesn't exist, pick the first child field
* 2. For a leaf form field, fall back to its field definition
* 3. For a combined form field, fall back to its first leaf child
* 4. If no field definition is found, return empty summary fields
*
* @param field The form field to get definition for
Expand Down
18 changes: 18 additions & 0 deletions packages/dataviews/src/dataform/stories/layout-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,12 @@ const LayoutPanelComponent = ( {
id: 'status',
label: 'Status & visibility',
children: [ 'status', 'password' ],
layout: getPanelLayoutFromStoryArgs( {
summary: [ 'status' ],
labelPosition,
openAs,
editVisibility,
} ),
},
'order',
'author',
Expand All @@ -365,11 +371,23 @@ const LayoutPanelComponent = ( {
id: 'discussion',
label: 'Discussion',
children: [ 'comment_status', 'ping_status' ],
layout: getPanelLayoutFromStoryArgs( {
summary: [ 'discussion' ],
labelPosition,
openAs,
editVisibility,
} ),
},
{
id: 'address1',
label: 'Combined address',
children: [ 'address1', 'address2', 'city' ],
layout: getPanelLayoutFromStoryArgs( {
summary: [ 'address1' ],
labelPosition,
openAs,
editVisibility,
} ),
},
{
id: 'flight_info',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,44 @@ describe( 'useFormValidity', () => {
expect( isValid ).toBe( false );
} );

// See https://github.com/WordPress/gutenberg/pull/81377#discussion_r3750984349
it( 'a combined field never resolves its own id against the field definitions', () => {
type Item = { isActive: boolean; a?: string };
const combinedFields: Field< Item >[] = [
// Shares the id of the form's combined field. It must be
// ignored: a combined field is a container, not a field, so
// neither its `isValid` nor its `isVisible` apply to the group.
{
id: 'group',
type: 'text',
isVisible: () => false,
isValid: { required: true },
},
{
id: 'a',
type: 'text',
isVisible: () => false,
isValid: { required: true },
},
];
const combinedForm = {
fields: [ { id: 'group', children: [ 'a' ] } ],
};
const item: Item = { isActive: false, a: undefined };
const {
result: {
current: { validity, isValid },
},
} = renderHook( () =>
useFormValidity( item, combinedFields, combinedForm )
);

// The hidden child `a` is skipped and the `group` definition's
// `required` rule is not applied to the combined field.
expect( validity ).toEqual( undefined );
expect( isValid ).toBe( true );
} );

it( 'a stale async result does not resurface after the field is hidden', async () => {
let resolveCustom: ( value: string | null ) => void = () => {};
const asyncFields: Field< TestItem >[] = [
Expand Down
17 changes: 4 additions & 13 deletions packages/dataviews/src/hooks/use-form-validity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,10 @@ function getFormFieldsToValidate< Item >(
return null;
}

const fieldDef = fieldsMap.get( formField.id );
if ( fieldDef ) {
const [ normalizedField ] = normalizeFields< Item >( [
fieldDef,
] );

return {
id: formField.id,
children: processedChildren,
field: normalizedField,
} satisfies FormFieldToValidate< Item >;
}

// A combined form field is a layout container, not a field:
// its id is never resolved against the field definitions, so
// no validation rules are attached to it. Only its children
// are validated.
Comment on lines +76 to +79

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to leave this comment to signal the change.

return {
id: formField.id,
children: processedChildren,
Expand Down
90 changes: 90 additions & 0 deletions phpunit/view-config-api-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,96 @@ public function tear_down() {
parent::tear_down();
}

/**
* Returns the form field with the given id from a view configuration.
*
* @param array $config The view configuration.
* @param string $id The form field id.
* @return array|null The form field, or null when absent.
*/
private function get_form_field( $config, $id ) {
foreach ( $config['form']['fields'] as $field ) {
if ( is_array( $field ) && isset( $field['id'] ) && $id === $field['id'] ) {
return $field;
}
}
return null;
}

/**
* The `status` and `discussion` groups of the default post type form declare
* their panel summary explicitly, for built-in and custom post types alike.
*
* @dataProvider data_default_form_post_types
*
* @param string $post_type The post type.
*/
public function test_default_form_groups_declare_summary( $post_type ) {
if ( ! post_type_exists( $post_type ) ) {
register_post_type( $post_type );
}

$config = gutenberg_get_entity_view_config( 'postType', $post_type );

foreach ( array( 'status', 'discussion' ) as $group ) {
$field = $this->get_form_field( $config, $group );
$this->assertNotNull( $field, "The `{$group}` group is present." );
$this->assertNotEmpty( $field['children'], "The `{$group}` group keeps its children." );
$this->assertSame(
array(
'type' => 'panel',
'summary' => $group,
),
$field['layout'],
"The `{$group}` group summary is explicit."
);
}

if ( 'page' !== $post_type && 'post' !== $post_type ) {
unregister_post_type( $post_type );
}
}

/**
* Data provider.
*
* @return array[]
*/
public function data_default_form_post_types() {
return array(
'page' => array( 'page' ),
'post' => array( 'post' ),
'custom post type' => array( 'summaries_cpt' ),
);
}

/**
* Post types with their own form do not receive the default form groups.
*
* @dataProvider data_post_types_with_own_form
*
* @param string $post_type The post type.
*/
public function test_own_form_post_types_do_not_get_default_groups( $post_type ) {
$config = gutenberg_get_entity_view_config( 'postType', $post_type );

$this->assertNull( $this->get_form_field( $config, 'status' ) );
$this->assertNull( $this->get_form_field( $config, 'discussion' ) );
}

/**
* Data provider.
*
* @return array[]
*/
public function data_post_types_with_own_form() {
return array(
'wp_block' => array( 'wp_block' ),
'wp_template' => array( 'wp_template' ),
'wp_template_part' => array( 'wp_template_part' ),
);
}

/**
* The default configuration exposes the documented shape for an unknown entity.
*/
Expand Down
8 changes: 8 additions & 0 deletions routes/post-list/quick-edit-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ export function QuickEditModal( {
{
id: 'status',
label: __( 'Status' ),
layout: {
type: 'panel',
summary: 'status',
},
children: [
{
id: 'status',
Expand All @@ -170,6 +174,10 @@ export function QuickEditModal( {
{
id: 'discussion',
label: __( 'Discussion' ),
layout: {
type: 'panel',
summary: 'discussion',
},
children: [
{
id: 'comment_status',
Expand Down
Loading
Loading