diff --git a/lib/compat/wordpress-7.2/view-config-api.php b/lib/compat/wordpress-7.2/view-config-api.php index 0eb33821d6f998..3f56990afa3b74 100644 --- a/lib/compat/wordpress-7.2/view-config-api.php +++ b/lib/compat/wordpress-7.2/view-config-api.php @@ -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', ), ), @@ -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; } @@ -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 @@ -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', diff --git a/packages/fields/CHANGELOG.md b/packages/fields/CHANGELOG.md index fa27dc42625ad3..281e743531476b 100644 --- a/packages/fields/CHANGELOG.md +++ b/packages/fields/CHANGELOG.md @@ -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 diff --git a/packages/fields/src/fields/description/index.tsx b/packages/fields/src/fields/description/index.tsx index c11e9a81ef1a06..ed07b1ddb2bd30 100644 --- a/packages/fields/src/fields/description/index.tsx +++ b/packages/fields/src/fields/description/index.tsx @@ -26,7 +26,7 @@ const descriptionField: Field< Template > = { render, Edit: { control: 'textarea', - rows: 4, + rows: 2, }, isVisible: isCustomTemplate, enableSorting: false, diff --git a/packages/fields/src/fields/excerpt/index.tsx b/packages/fields/src/fields/excerpt/index.tsx index 09a3a5911feb4b..cee4e6f131a4aa 100644 --- a/packages/fields/src/fields/excerpt/index.tsx +++ b/packages/fields/src/fields/excerpt/index.tsx @@ -22,23 +22,17 @@ const excerptField: Field< BasePost > = { ), 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 ? ( - { excerpt } + { decodeEntities( excerpt ) } - ); + ) : null; }, Edit: { control: 'textarea', - rows: 4, + rows: 2, }, enableSorting: false, filterBy: false, diff --git a/packages/fields/src/fields/pattern-description/index.tsx b/packages/fields/src/fields/pattern-description/index.tsx index b309d8d241ad26..7fcc6d78247afd 100644 --- a/packages/fields/src/fields/pattern-description/index.tsx +++ b/packages/fields/src/fields/pattern-description/index.tsx @@ -23,7 +23,7 @@ const patternDescriptionField: Field< Pattern > = { }, Edit: { control: 'textarea', - rows: 4, + rows: 2, }, enableSorting: false, enableHiding: false, diff --git a/phpunit/view-config-api-test.php b/phpunit/view-config-api-test.php index 8f6a185e1e33c4..99b4f6601c1d07 100644 --- a/phpunit/view-config-api-test.php +++ b/phpunit/view-config-api-test.php @@ -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 * @@ -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 ); } diff --git a/test/e2e/specs/editor/various/post-summary-dataform/post-summary.spec.js b/test/e2e/specs/editor/various/post-summary-dataform/post-summary.spec.js index 1ac8c90bbd2339..ae36c7fac23ec0 100644 --- a/test/e2e/specs/editor/various/post-summary-dataform/post-summary.spec.js +++ b/test/e2e/specs/editor/various/post-summary-dataform/post-summary.spec.js @@ -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( @@ -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 ); } ); } @@ -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( @@ -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( @@ -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 @@ -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( () => @@ -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 @@ -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(); } ); } ); diff --git a/test/e2e/specs/editor/various/post-summary-dataform/sidebar.spec.js b/test/e2e/specs/editor/various/post-summary-dataform/sidebar.spec.js index 2d37ae5882c649..df95098ac1071f 100644 --- a/test/e2e/specs/editor/various/post-summary-dataform/sidebar.spec.js +++ b/test/e2e/specs/editor/various/post-summary-dataform/sidebar.spec.js @@ -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',