Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
787f90e
Post summary: Show the placeholder when the excerpt is empty
oandregal Oct 28, 2026
86649ad
Post summary: Always show the excerpt's edit button
oandregal Oct 28, 2026
97b744d
DataForm: Mute the panel placeholder of an empty value
oandregal Oct 28, 2026
3b87e80
Revert "Post summary: Always show the excerpt's edit button"
oandregal Oct 28, 2026
499cc30
DataViews: Link the placeholder changelog entry to its pull request
oandregal Oct 28, 2026
ef7b9f2
Add the backport changelog entry for the excerpt placeholder
oandregal Oct 28, 2026
020635b
DataForm: Show the panel placeholder when the render output is empty
oandregal Oct 30, 2026
afaa5d6
Core fields: Show the author placeholder for a post without a known a…
oandregal Oct 30, 2026
e26862b
Post summary: Show the placeholder when the post has no author
oandregal Oct 30, 2026
2e967eb
DataForm: Keep the emphasized weight for the panel placeholder
oandregal Oct 30, 2026
44bb0e1
Core fields: Wrap the excerpt placeholder in parentheses
oandregal Oct 30, 2026
837d757
Core fields: Render the excerpt with the typography of other values
oandregal Oct 30, 2026
c18fa15
Update excerpt placeholder
oandregal Oct 30, 2026
27a14bc
Fix e2e test
oandregal Oct 30, 2026
00d15f8
Core fields: Wrap the description placeholders in parentheses
oandregal Nov 3, 2026
af6cdd9
Core fields: Render the descriptions with the typography of other values
oandregal Nov 3, 2026
ffc2c77
Templates: Show the description placeholder when the description is e…
oandregal Nov 3, 2026
26194ec
Core fields: Show the author placeholder for media without a known au…
oandregal Nov 3, 2026
c53d353
Media editor: Show the placeholder of the author row when the media h…
oandregal Nov 3, 2026
3cee79d
Post list: Embed the author of media items
oandregal Nov 3, 2026
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/15120.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/15120
Comment thread
oandregal marked this conversation as resolved.
Resolved

* https://github.com/WordPress/gutenberg/pull/85842
116 changes: 114 additions & 2 deletions lib/compat/wordpress-7.2/view-config-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ function _gutenberg_add_reading_settings_to_wp_template_view_config( $data ) {
array(
'id' => 'description',
'layout' => array(
'type' => 'panel',
'labelPosition' => 'top',
'type' => 'panel',
'labelPosition' => 'top',
'showPlaceholderIfEmpty' => true,
),
),
array(
Expand Down Expand Up @@ -324,6 +325,117 @@ function gutenberg_register_default_posttype_form_summaries_7_2( $post_type ) {
}
add_action( 'registered_post_type', 'gutenberg_register_default_posttype_form_summaries_7_2' );

/**
* Shows the placeholder of the `excerpt` field in its panel row when the
* excerpt is empty.
*
* The field renders nothing for an empty value, so DataViews lists stay empty,
* but the panel row then showed only its label. The patch merges into the
* existing `excerpt` member by id, leaving the rest of its layout 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_update_excerpt_layout_in_view_config( $data ) {
return $data->merge(
array(
'form' => array(
'fields' => array(
array(
'id' => 'excerpt',
'layout' => array(
'type' => 'panel',
'showPlaceholderIfEmpty' => true,
),
),
),
),
),
1
);
}

/**
* Layers the `excerpt` layout on top of the view configuration of every post
* type whose form lists the `excerpt` field: those using the default form,
* including custom post types registered at any point, and patterns.
*
* A member that is absent would be appended instead of merged, so the other
* post types providing their own form are skipped.
*
* @param string $post_type The post type being registered.
*/
function gutenberg_register_excerpt_layout_7_2( $post_type ) {
if (
'wp_block' !== $post_type &&
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_update_excerpt_layout_in_view_config',
6,
1
);
}
add_action( 'registered_post_type', 'gutenberg_register_excerpt_layout_7_2' );

/**
* Shows the placeholder of the `author` field in its panel row when the post
* has no author, as the post summary did before it moved to the form.
*
* @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_update_author_layout_in_view_config( $data ) {
return $data->merge(
array(
'form' => array(
'fields' => array(
array(
'id' => 'author',
'layout' => array(
'type' => 'panel',
'showPlaceholderIfEmpty' => true,
),
),
),
),
),
1
);
}

/**
* Layers the `author` layout on top of the view configuration of every post
* type whose form lists the `author` field at its top level: those using the
* default form, including custom post types registered at any point, and
* attachments.
*
* A member that is absent would be appended instead of merged, so the other
* post types providing their own form are skipped.
*
* @param string $post_type The post type being registered.
*/
function gutenberg_register_author_layout_7_2( $post_type ) {
if (
'attachment' !== $post_type &&
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_update_author_layout_in_view_config',
6,
1
);
}
add_action( 'registered_post_type', 'gutenberg_register_author_layout_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
9 changes: 5 additions & 4 deletions packages/core-fields/src/attachment/author/field.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
*/

return array(
'type' => 'integer',
'label' => __( 'Author' ),
'filterBy' => array(
'type' => 'integer',
'label' => __( 'Author' ),
'placeholder' => __( '(No author)' ),
'filterBy' => array(
'operators' => array( 'isAny', 'isNone' ),
),
'readOnly' => true,
'readOnly' => true,
);
7 changes: 7 additions & 0 deletions packages/core-fields/src/attachment/author/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ export default function AuthorView( { item }: { item: MediaItem } ) {
}
};

// Some media have no author, and the author id of others matches no user
// listed as an author, like a deleted user. A panel row shows the field's
// placeholder for both.
if ( ! text ) {
return null;
}

return (
<Stack direction="row" align="flex-start" justify="flex-start">
{ !! imageUrl && (
Expand Down
7 changes: 4 additions & 3 deletions packages/core-fields/src/post_type_supports/author/field.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
*/

return array(
'type' => 'integer',
'label' => __( 'Author' ),
'filterBy' => array(
'type' => 'integer',
'label' => __( 'Author' ),
'placeholder' => __( '(No author)' ),
'filterBy' => array(
'operators' => array( 'isAny', 'isNone' ),
),
);
36 changes: 24 additions & 12 deletions packages/core-fields/src/post_type_supports/author/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,32 @@ export default function AuthorView( { item }: { item: PostWithAuthor } ) {
const shouldFetch = Boolean(
authorId && ( ! embeddedAuthorId || authorId !== embeddedAuthorId )
);
const author = useSelect(
const { author, hasResolved } = useSelect(
( select ) => {
if ( ! shouldFetch ) {
return null;
return { author: null, hasResolved: true };
}
const { getEntityRecords } = select( coreStore );
const { getEntityRecords, hasFinishedResolution } =
select( coreStore );
// Query the collection with `who: 'authors'` instead of calling
// `getEntityRecord`, because the single user endpoint denies
// access to authors without published posts for users who can't
// list users. See https://core.trac.wordpress.org/ticket/56429.
return (
getEntityRecords< User >( 'root', 'user', {
include: [ authorId ],
who: 'authors',
context: 'view',
} )?.[ 0 ] ?? null
);
const query = {
include: [ authorId ],
who: 'authors',
context: 'view',
};
return {
author:
getEntityRecords< User >( 'root', 'user', query )?.[ 0 ] ??
null,
hasResolved: hasFinishedResolution( 'getEntityRecords', [
'root',
'user',
query,
] ),
};
},
[ authorId, shouldFetch ]
);
Expand All @@ -48,8 +57,11 @@ export default function AuthorView( { item }: { item: PostWithAuthor } ) {
author?.avatar_urls?.[ 48 ] ||
item?._embedded?.author?.[ 0 ]?.avatar_urls?.[ 48 ];
const [ isImageLoaded, setIsImageLoaded ] = useState( false );
// Some items have no author, like the patterns of themes.
if ( ! authorId ) {
// Some items have no author, like the patterns of themes, and the author
// id of others matches no user listed as an author, like a deleted user
// or one whose role can no longer edit posts. A panel row shows the
// field's placeholder for both.
if ( ! authorId || ( ! text && hasResolved ) ) {
return null;
}
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
return array(
'type' => 'text',
'label' => __( 'Excerpt' ),
'placeholder' => __( 'Add an excerpt' ),
'placeholder' => __( '(No excerpt)' ),
Comment thread
oandregal marked this conversation as resolved.
Resolved
'Edit' => array(
'control' => 'textarea',
'rows' => 4,
Expand Down
9 changes: 5 additions & 4 deletions packages/core-fields/src/post_type_supports/excerpt/field.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { decodeEntities } from '@wordpress/html-entities';
import { __ } from '@wordpress/i18n';
import { Link, Text } from '@wordpress/ui';
import { Link } from '@wordpress/ui';
import type { FieldsScriptParts } from '../../types';
import styles from './style.module.css';

Expand All @@ -22,14 +22,15 @@ export const fieldExtensions: FieldsScriptParts< PostWithExcerpt >[ string ] = {
{ __( 'Learn more about manual excerpts' ) }
</Link>
),
// Shows the first three lines of the excerpt.
// Shows the first three lines of the excerpt, as plain text that takes the
// typography of where it renders, like the values of other fields.
render: ( { item } ) => {
const excerpt =
typeof item.excerpt === 'string' ? item.excerpt : item.excerpt?.raw;
return excerpt ? (
<Text className={ styles.excerpt }>
<span className={ styles.excerpt }>

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.

Changing from Text to span so that the field has the same weight as any other field.

{ decodeEntities( excerpt ) }
</Text>
</span>
) : null;
},
};
2 changes: 1 addition & 1 deletion packages/core-fields/src/wp_block/description/field.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'id' => 'excerpt',
'type' => 'text',
'label' => __( 'Description' ),
'placeholder' => __( 'Add a description' ),
'placeholder' => __( '(No description)' ),
'Edit' => array(
'control' => 'textarea',
'rows' => 4,
Expand Down
5 changes: 3 additions & 2 deletions packages/core-fields/src/wp_block/description/field.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { decodeEntities } from '@wordpress/html-entities';
import { Text } from '@wordpress/ui';
import type { FieldsScriptParts } from '../../types';

type Pattern = {
Expand All @@ -19,8 +18,10 @@ function getPatternDescription( item: Pattern ) {
*/
export const fieldExtensions: FieldsScriptParts< Pattern >[ string ] = {
getValue: ( { item } ) => getPatternDescription( item ),
// Renders as plain text that takes the typography of where it renders,
// like the values of other fields.
render: ( { item } ) => {
const description = getPatternDescription( item );
return description ? <Text>{ description }</Text> : null;
return description ? <span>{ description }</span> : null;
},
};
2 changes: 1 addition & 1 deletion packages/core-fields/src/wp_template/description/field.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
return array(
'type' => 'text',
'label' => __( 'Description' ),
'placeholder' => __( 'Add a description' ),
'placeholder' => __( '(No description)' ),
'Edit' => array(
'control' => 'textarea',
'rows' => 4,
Expand Down
6 changes: 3 additions & 3 deletions packages/core-fields/src/wp_template/description/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { decodeEntities } from '@wordpress/html-entities';
import { Text } from '@wordpress/ui';

/**
* The properties of a template the description fields read.
Expand Down Expand Up @@ -33,13 +32,14 @@ export const getValue = ( { item }: { item: TemplateWithDescription } ) =>
decodeEntities( item.description || '' );

/**
* Renders the description of a template.
* Renders the description of a template, as plain text that takes the
* typography of where it renders, like the values of other fields.
*
* @param props The props.
* @param props.item The template.
* @return The description, if any.
*/
export const render = ( { item }: { item: TemplateWithDescription } ) => {
const { description } = item;
return description ? <Text>{ decodeEntities( description ) }</Text> : null;
return description ? <span>{ decodeEntities( description ) }</span> : null;
};
2 changes: 2 additions & 0 deletions packages/dataviews/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
- Use the design system outline for keyboard focus on grid cards ([#85364](https://github.com/WordPress/gutenberg/pull/85364)).
- Simplify filter selection indicators and remove their hover colors ([#85191](https://github.com/WordPress/gutenberg/pull/85191)).
- Use design system focus ring for filter chips & prevent text from touching remove button ([#85374](https://github.com/WordPress/gutenberg/pull/85374)).
- DataForm: Mute the placeholder that the `panel` layout shows for an empty value, so it no longer looks like a value ([#85842](https://github.com/WordPress/gutenberg/pull/85842)).
- DataForm: The `showPlaceholderIfEmpty` option of the `panel` layout also shows the placeholder when the field's `render` output is empty, like for an id matching no record ([#85842](https://github.com/WordPress/gutenberg/pull/85842)).

### Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion packages/dataviews/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2253,7 +2253,7 @@ For example:
- `type`: `panel`. Required.
- `labelPosition`: one of `side`, `top`, or `none`. Optional. `side` by default.
- `editVisibility`: one of `always`, or `on-hover`. Optional. `on-hover` by default.
- `showPlaceholderIfEmpty`: boolean. Optional. `false` by default. Whether the summary shows the field's `placeholder` instead of its `render` output when the field's value is `undefined`, `null`, or an empty string.
- `showPlaceholderIfEmpty`: boolean. Optional. `false` by default. Whether the summary shows the field's `placeholder` instead of its `render` output when the field's value is `undefined`, `null`, or an empty string, or when the `render` output is empty, like for an id matching no record.
- `openAs`: one of `dropdown`, `modal`. Optional. `dropdown` by default.
- `summary`: Summary field configuration. Optional. Specifies which field(s) to display in the panel header. Can be:
- A string (single field ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
opacity: 1;
}

.dataforms-layouts-panel__field-label {
.dataforms-layouts-panel__field-label,
.dataforms-layouts-panel__field-placeholder {
color: var(--wpds-color-foreground-interactive-brand);
}
}
Expand Down Expand Up @@ -155,6 +156,27 @@
}
}

// A placeholder stands in for an empty value, so it is muted by color. It keeps
// the emphasized weight of values, the cue that the row is editable, which is
// all that tells it apart from the label when forced colors replace the color.
.dataforms-layouts-panel__field-placeholder {
color: var(--wpds-color-foreground-content-neutral-weak);
}

// Wraps the render output of a value followed by its placeholder, without
// adding a box of its own.
.dataforms-layouts-panel__field-value {
display: contents;

> * {
min-width: 0;
}

&:not(:empty) + .dataforms-layouts-panel__field-placeholder {
display: none;
}
}

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 is connected with the changes in summary-button.jsx so that we can display the placeholder when the field has tried fetching data but still returns nothing (e.g., author field that didn't found the author).

I tried alternatives such as moving the decision to the field render: this is unsatisfactory because we only want the placeholder when in the panel mode and only if the showPlaceholderIfEmpty form prop is enabled. The field must remain view/form agnostic.


.dataforms-layouts-panel__field-trigger--label-top
.dataforms-layouts-panel__field-label {
width: 100%;
Expand Down
Loading
Loading