Skip to content
Closed
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
57 changes: 50 additions & 7 deletions lib/compat/wordpress-7.2/view-config-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function _gutenberg_add_reading_settings_to_wp_template_view_config( $data ) {
array(
'id' => 'description',
'layout' => array(
'type' => 'panel',
'type' => 'regular',
'labelPosition' => 'top',
),
),
Expand Down Expand Up @@ -152,17 +152,48 @@ function _gutenberg_add_group_summaries_to_default_posttype_form( $data ) {
}

/**
* 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.
* Renders the `excerpt` field inline with the regular layout instead of the
* panel summary and its edit popover.
*
* The textarea and its placeholder show that the field is editable even when
* the excerpt is empty, which the panel summary cannot without a rendered
* value. The patch merges into the existing member by id, leaving its position
* in 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_use_regular_layout_for_excerpt( $data ) {
return $data->merge(
array(
'form' => array(
'fields' => array(
array(
'id' => 'excerpt',
'layout' => array(
'type' => 'regular',
'labelPosition' => 'top',
),
),
),
),
),
1
);
}

/**
* Layers the group summaries and the regular excerpt layout 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
* The callbacks merge 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 ) {
function gutenberg_register_default_posttype_form_layers_7_2( $post_type ) {
if ( in_array( $post_type, GUTENBERG_VIEW_CONFIG_POST_TYPES_WITH_OWN_FORM, true ) ) {
return;
}
Expand All @@ -173,8 +204,14 @@ function gutenberg_register_default_posttype_form_summaries_7_2( $post_type ) {
6,
1
);
add_filter(
gutenberg_get_entity_view_config_hook_name( 'postType', $post_type ),
'_gutenberg_use_regular_layout_for_excerpt',
6,
1
);
}
add_action( 'registered_post_type', 'gutenberg_register_default_posttype_form_summaries_7_2' );
add_action( 'registered_post_type', 'gutenberg_register_default_posttype_form_layers_7_2' );

/**
* Registers the entity view configuration filters that layer on top of the base
Expand All @@ -189,6 +226,12 @@ function gutenberg_register_entity_view_config_filters_7_2() {
5,
1
);
add_filter(
gutenberg_get_entity_view_config_hook_name( 'postType', 'wp_block' ),
'_gutenberg_use_regular_layout_for_excerpt',
6,
1
);
add_filter(
gutenberg_get_entity_view_config_hook_name( 'postType', 'wp_template' ),
'_gutenberg_add_reading_settings_to_wp_template_view_config',
Expand Down
1 change: 1 addition & 0 deletions packages/fields/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Enhancements

- Excerpt field: render nothing for an empty excerpt instead of the `Add an excerpt` placeholder text. Start the textarea of the excerpt, description, and pattern description fields at two rows instead of four. ([#82444](https://github.com/WordPress/gutenberg/pull/82444))
- Append an ellipsis (`…`) to the labels of the actions that open a dialog requiring further input or confirmation (`Delete…`, `Trash…`, `Permanently delete…`, `Rename…`, `Duplicate…`, `Reset…`, `Order…`), following the menu ellipsis guideline. The dialog titles keep the ellipsis-free wording. ([#81994](https://github.com/WordPress/gutenberg/pull/81994))

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion packages/fields/src/fields/description/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const descriptionField: Field< Template > = {
render,
Edit: {
control: 'textarea',
rows: 4,
rows: 2,
},
isVisible: isCustomTemplate,
enableSorting: false,
Expand Down
18 changes: 6 additions & 12 deletions packages/fields/src/fields/excerpt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,17 @@ const excerptField: Field< BasePost > = {
</ExternalLink>
),
render: ( { item } ) => {
let excerpt;
if ( typeof item.excerpt === 'string' ) {
excerpt = !! item.excerpt
? decodeEntities( item.excerpt )
: __( 'Add an excerpt' );
} else {
excerpt = decodeEntities( item.excerpt?.raw || '' );
}
return (
const excerpt =
typeof item.excerpt === 'string' ? item.excerpt : item.excerpt?.raw;
return excerpt ? (
<WCText align="left" numberOfLines={ 3 } truncate>
{ excerpt }
{ decodeEntities( excerpt ) }
</WCText>
);
) : null;
},
Edit: {
control: 'textarea',
rows: 4,
rows: 2,
},
enableSorting: false,
filterBy: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/fields/src/fields/pattern-description/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const patternDescriptionField: Field< Pattern > = {
},
Edit: {
control: 'textarea',
rows: 4,
rows: 2,
},
enableSorting: false,
enableHiding: false,
Expand Down
13 changes: 12 additions & 1 deletion phpunit/view-config-api-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ private function get_form_field( $config, $id ) {

/**
* The `status` and `discussion` groups of the default post type form declare
* their panel summary explicitly, for built-in and custom post types alike.
* their panel summary explicitly, and the `excerpt` field renders inline with
* the regular layout, for built-in and custom post types alike.
*
* @dataProvider data_default_form_post_types
*
Expand All @@ -116,6 +117,16 @@ public function test_default_form_groups_declare_summary( $post_type ) {
);
}

$excerpt = $this->get_form_field( $config, 'excerpt' );
$this->assertSame(
array(
'type' => 'regular',
'labelPosition' => 'top',
),
$excerpt['layout'],
'The `excerpt` field renders inline with the regular layout.'
);

if ( 'page' !== $post_type && 'post' !== $post_type ) {
unregister_post_type( $post_type );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,12 @@ test.describe( 'Post Summary', () => {
page,
tab: 'Pattern',
} );
const fields = getPatternSummaryFields( { page, summary } );
const fields = getPatternSummaryFields( { summary } );

await expect(
fields.description.row.getByText( INITIAL_DESCRIPTION, {
exact: true,
} )
).toBeVisible();
await expect( fields.description.textbox ).toHaveCount( 0 );

await fields.description.editButton.click();
await expect( fields.description.textbox ).toBeVisible();
await expect( fields.description.textbox ).toHaveValue(
INITIAL_DESCRIPTION
);
await fields.description.textbox.fill( UPDATED_DESCRIPTION );
await page.keyboard.press( 'Escape' );
await expect(
fields.description.row.getByText( UPDATED_DESCRIPTION, {
exact: true,
} )
).toBeVisible();

await expect( fields.revisions.row ).toBeVisible();
await expect(
Expand All @@ -90,13 +78,9 @@ test.describe( 'Post Summary', () => {
tab: 'Pattern',
} );
await expect(
getPatternSummaryFields( {
page,
summary: reloadedSummary,
} ).description.row.getByText( UPDATED_DESCRIPTION, {
exact: true,
} )
).toBeVisible();
getPatternSummaryFields( { summary: reloadedSummary } )
.description.textbox
).toHaveValue( UPDATED_DESCRIPTION );
} );
}

Expand All @@ -113,7 +97,7 @@ test.describe( 'Post Summary', () => {
page,
tab: 'Pattern',
} );
const fields = getPatternSummaryFields( { page, summary } );
const fields = getPatternSummaryFields( { summary } );

await expect( fields.title ).toHaveText( title );
await expect(
Expand All @@ -139,7 +123,7 @@ test.describe( 'Post Summary', () => {
page,
tab: 'Pattern',
} );
const fields = getPatternSummaryFields( { page, summary } );
const fields = getPatternSummaryFields( { summary } );

await expect( fields.title ).toHaveText( title );
await expect(
Expand Down Expand Up @@ -200,30 +184,19 @@ test.describe( 'Post Summary', () => {
await expect( modal ).toBeHidden();
}

function getPatternSummaryFields( { page, summary } ) {
function getPatternSummaryFields( { summary } ) {
return {
title: summary.locator( '.editor-post-card-panel__title-name' ),
description: getDescriptionField( { page, summary } ),
description: {
textbox: summary.getByRole( 'textbox', {
name: 'Description',
} ),
},
revisions: getRevisionsField( { summary } ),
syncStatus: getSyncStatusField( { summary } ),
};
}

function getDescriptionField( { page, summary } ) {
const editButton = summary.getByRole( 'button', {
name: 'Edit Description',
} );

return {
// The field row also renders the current value next to the edit button.
row: editButton.locator( '..' ),
editButton,
// The edit popover is portaled outside the summary, so query it
// from the page by the textarea's accessible label.
textbox: page.getByRole( 'textbox', { name: 'Description' } ),
};
}

function getRevisionsField( { summary } ) {
return {
row: summary
Expand Down Expand Up @@ -408,22 +381,16 @@ test.describe( 'Post Summary', () => {
} ) => {
await admin.createNewPost();
const summary = await openPostSummary( { editor, page } );
const excerpt = summary.getByRole( 'textbox', { name: 'Excerpt' } );

await expect(
summary.getByText( 'Add an excerpt', { exact: true } )
).toBeVisible();
await expect( excerpt ).toHaveValue( '' );
await expect( excerpt ).toHaveAttribute(
'placeholder',
'Add an excerpt'
);

await summary
.getByRole( 'button', { name: 'Edit Excerpt' } )
.click();
await page
.getByRole( 'textbox', { name: 'Excerpt' } )
.fill( 'A DataForm excerpt.' );
await page.keyboard.press( 'Escape' );
await excerpt.fill( 'A DataForm excerpt.' );

await expect(
summary.getByText( 'A DataForm excerpt.', { exact: true } )
).toBeVisible();
await expect
.poll( () =>
page.evaluate( () =>
Expand Down Expand Up @@ -574,13 +541,13 @@ test.describe( 'Post Summary', () => {
} ) => {
await admin.createNewPost();
const summary = await openPostSummary( { editor, page } );
const excerptButton = summary.getByRole( 'button', {
name: 'Edit Excerpt',
const excerptField = summary.getByRole( 'textbox', {
name: 'Excerpt',
} );
const discussionButton = summary.getByRole( 'button', {
name: 'Edit Discussion',
} );
await expect( excerptButton ).toBeVisible();
await expect( excerptField ).toBeVisible();
await expect( discussionButton ).toBeVisible();

await page
Expand All @@ -599,7 +566,7 @@ test.describe( 'Post Summary', () => {
.uncheck();
await preferences.getByRole( 'button', { name: 'Close' } ).click();

await expect( excerptButton ).toBeHidden();
await expect( excerptField ).toBeHidden();
await expect( discussionButton ).toBeHidden();
} );
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ test.describe( 'Sidebar (DataForm inspector)', () => {
'Tags',
] );
// Also check 'panels' that are not rendered as TabPanels.
const postExcerptPanel = page.getByRole( 'button', {
name: 'Edit Excerpt',
const postExcerptPanel = page.getByRole( 'textbox', {
name: 'Excerpt',
} );
const postFeaturedImagePanel = page.getByRole( 'button', {
name: 'Set featured image',
Expand Down
Loading