Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
cdc80be
Experimental: Expand Editor Inspector: Use DataForm experiment to tem…
ntsekouras Mar 31, 2026
c4a2e43
use description field in templates list(site editor)
ntsekouras Apr 1, 2026
3311bff
get_form_for_template
ntsekouras Apr 1, 2026
8a16dea
remove label for readonly description in form
ntsekouras Apr 1, 2026
31cda3f
add posts per page field
ntsekouras Apr 2, 2026
a0fe2c6
add siteDiscussionField field
ntsekouras Apr 2, 2026
788cefc
add blogTitleField field
ntsekouras Apr 2, 2026
064f87f
add `lastEditedDateField` field
ntsekouras Apr 3, 2026
612ca55
show lastEditedDateField only when is modified
ntsekouras Apr 3, 2026
8172e63
remove dv tooltip change
ntsekouras Apr 3, 2026
88b491a
update descriptionField to handle only templates for now
ntsekouras Apr 3, 2026
62e67cc
use Text from ui
ntsekouras Jun 5, 2026
499f20a
add description-readonly field
ntsekouras Jun 5, 2026
6c23076
update comment
ntsekouras Jun 5, 2026
426bc77
port the form configs in their new place (after the rebase)
ntsekouras Jun 17, 2026
0ba62aa
use a single TemplateHomeSettings form for the extra niche fields
ntsekouras Jun 17, 2026
94f0b77
do not register SITE_FIELDS for templates
ntsekouras Jun 17, 2026
a363878
php lint
ntsekouras Jun 17, 2026
7c08f5c
remove summary button change
ntsekouras Jun 18, 2026
a98e5b8
Consolidate into a single DataForm
oandregal Jun 18, 2026
b3d5d5c
rename the new fields + move nested date fields
ntsekouras Jun 18, 2026
fc0a25d
fix imports and add revisions in templates form
ntsekouras Jun 18, 2026
446f584
rename description_readonly
ntsekouras Jun 18, 2026
5040e72
move revision field up
ntsekouras Jun 18, 2026
908adc5
Bind fields to the namespace in the consumer (DataFormSummary)
oandregal Jun 19, 2026
8cee1e4
add `isVisible` in ENTITIES config for future additions
ntsekouras Jun 19, 2026
440bccf
fix available_templates augmented data for classic themes `template` …
ntsekouras Jun 19, 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
1 change: 1 addition & 0 deletions backport-changelog/7.1/11272.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ https://github.com/WordPress/wordpress-develop/pull/11272
* https://github.com/WordPress/gutenberg/pull/77290
* https://github.com/WordPress/gutenberg/pull/78977
* https://github.com/WordPress/gutenberg/pull/79195
* https://github.com/WordPress/gutenberg/pull/76934
35 changes: 35 additions & 0 deletions lib/compat/wordpress-7.1/view-config-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,41 @@ function _gutenberg_get_entity_view_config_post_type_wp_template( $config ) {

$config['view_list'] = array_merge( $view_list, $registered_authors, $user_authors );

$config['form'] = array(
'layout' => array( 'type' => 'panel' ),
'fields' => array(
array(
'id' => 'description',
'layout' => array(
'type' => 'panel',
'labelPosition' => 'top',
),
),
array(
'id' => 'description_readonly',
'layout' => array(
'type' => 'regular',
'labelPosition' => 'none',
),
),
array(
'id' => 'last_edited_date',
'layout' => array(
'type' => 'panel',
'labelPosition' => 'none',
),
),
'revisions',
// The following fields are only meaningful in the `home`/`index`
// template summary. They edit other entities (`root/site` and the
// posts page); the editor merges those records into the form data
// under a namespace and controls when the fields are shown.
'posts_page_title',
'posts_per_page',
'default_comment_status',
),
);

return $config;
}
if ( has_filter( 'get_entity_view_config_postType_wp_template', '_wp_get_entity_view_config_post_type_wp_template' ) ) {
Expand Down
26 changes: 17 additions & 9 deletions packages/edit-site/src/components/page-templates/index-legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import AddNewTemplate from '../add-new-template-legacy';
import { TEMPLATE_POST_TYPE } from '../../utils/constants';
import { unlock } from '../../lock-unlock';
import { useEditPostAction } from '../dataviews-actions';
import { authorField, descriptionField, previewField } from './fields';
import { authorField, previewField } from './fields';

const { usePostActions, templateTitleField } = unlock( editorPrivateApis );
const { usePostActions, usePostFields } = unlock( editorPrivateApis );
const { useHistory, useLocation } = unlock( routerPrivateApis );
const { useEntityRecordsWithPermissions } = unlock( corePrivateApis );

Expand Down Expand Up @@ -97,18 +97,26 @@ export default function PageTemplates() {
} ) );
}, [ records ] );

const fields = useMemo(
() => [
const postFields = usePostFields( { postType: TEMPLATE_POST_TYPE } );
const fields = useMemo( () => {
const __fields = [
previewField,
templateTitleField,
descriptionField,
{
...authorField,
elements: authors,
},
],
[ authors ]
);
];
// TODO: Only `description` and `title` are sourced from the shared
// `@wordpress/fields` registry so far. The remaining local fields
// (e.g. `previewField`, `authorField`) should also be evaluated for
// migration to the shared registry.
return [
...__fields,
...( postFields || [] ).filter( ( field ) =>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is the kind of custom code we aim to remove with the entity-based config. What do we need to remove it? What's blocking us from migrating author&preview and then remove all of this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It also highlights the issues that come with having description and description_readonly:

Image

Note how the two "description" fields are visible in the view config properties. We need to set enableHiding: false for description_readonly (though, mid-term, we may want to revisit this because it's a bit weird to have to do that to prevent the field from being displayed when it's not part of the view.fields list).

@ntsekouras ntsekouras Jun 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What's blocking us from migrating author&preview and then remove all of this?

I haven't checked that as part of this PR (to keep smaller), but I'm planning to do so separately.

Note how the two "description" fields are visible in the view config properties.

How did you encounter that? Right now the fields passed in template list don't include the readonly description. That field is added only in the form config.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's fine to do it in follow-ups, but we need tracking of these things so that we know what needs to be done. The goal is to have a general system that doesn't need custom code (that 3rd parties cannot add themselves).

How did you encounter that?

I removed the filter :)

[ 'description', 'title' ].includes( field.id )
),
];
}, [ authors, postFields ] );

const { data, paginationInfo } = useMemo( () => {
return filterSortAndPaginate( records, view, fields );
Expand Down
215 changes: 191 additions & 24 deletions packages/editor/src/components/sidebar/dataform-post-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,72 @@ import revisionsField from '../../dataviews/fields/revisions';

const EMPTY_FORM = { layout: { type: 'panel' }, fields: [] };

// Some post types expose summary fields that edit entities other than the one
// being edited. Keyed by the post type that needs them, the related records are
// merged into the form data under a `${ kind }_${ name }` namespace key so that
// a single DataForm can read and write all of them, and edits to those keys are
// routed back to their entity.
//
// The fields themselves are namespace-agnostic: they read and write a plain
// record. The `fields` list ties each one to the entity it edits, and this
// component overrides their `getValue`/`setValue`/`render` to operate on the
// namespaced record, plus their `isVisible` to only show where that record is
// present (e.g. the `home`/`index` template summary).
//
// Currently only `wp_template` uses this: `posts_per_page` and
// `default_comment_status` target `root/site`, and `posts_page_title` targets
// the posts page (the `page` assigned as `page_for_posts`).
const ENTITIES = {
Comment thread
ntsekouras marked this conversation as resolved.
Resolved
wp_template: {
root_site: {
kind: 'root',
name: 'site',
fields: [ 'posts_per_page', 'default_comment_status' ],
isVisible: ( item ) =>
[ 'home', 'index' ].includes( item.slug ?? '' ),
},
posttype_page: {
kind: 'postType',
name: 'page',
getId: ( select ) =>
select( coreDataStore ).getEditedEntityRecord( 'root', 'site' )
?.page_for_posts,
fields: [ 'posts_page_title' ],
isVisible: ( item ) =>
[ 'home', 'index' ].includes( item.slug ?? '' ),
},
},
};

// Rebinds a namespace-agnostic field to the namespaced record it edits. Every
// field callback that receives the form `item` is redirected to the
// `item[ namespace ]` sub-record so the field operates on its own entity:
// `getValue`/`setValue`/`render` here, and the rest indirectly because they all
// funnel through the (remapped) `getValue` (default `render`, `getValueFormatted`
// and `isValid` range/`custom` validation). Edits are wrapped back under the
// namespace key. The caller-supplied `isVisible` encodes entity-specific
// conditions (e.g. only for `home`/`index` templates); the generic guard
// `!! item[ namespace ]` ensures the field is hidden when the sub-record
// hasn't been fetched.
function bindFieldToNamespace( field, namespace, isVisible = () => true ) {
const subItem = ( item ) => item?.[ namespace ] ?? {};
return {
...field,
getValue: ( { item } ) =>
field.getValue
? field.getValue( { item: subItem( item ) } )
: subItem( item )[ field.id ],
setValue: ( { item, value } ) => ( {
[ namespace ]: field.setValue( { item: subItem( item ), value } ),
} ),
render: field.render
? ( props ) =>
field.render( { ...props, item: subItem( props.item ) } )
: undefined,
isVisible: ( item ) => isVisible( item ) && !! item[ namespace ],
};
}

export default function DataFormPostSummary( { onActionPerformed } ) {
const { postType, postId } = useSelect( ( select ) => {
const { getCurrentPostType, getCurrentPostId } = select( editorStore );
Expand Down Expand Up @@ -51,33 +117,102 @@ export default function DataFormPostSummary( { onActionPerformed } ) {

const templatePanelMode = usePostTemplatePanelMode();

const availableTemplates = useSelect( ( select ) => {
if ( select( coreDataStore ).getCurrentTheme()?.is_block_theme ) {
return null;
}
return (
select( editorStore ).getEditorSettings().availableTemplates ?? {}
);
}, [] );
// Assemble every piece of supplementary data merged into the form `data`
// alongside the post record: read-only editor data that the post's own
// fields consume (e.g. the `template` field's `available_templates` in
// classic themes), and the records of other entities targeted by namespaced
// fields (keyed by `${ kind }_${ name }`) together with the id used to
// persist edits back to each one.
const { entityData, entityIds, availableTemplates } = useSelect(
( select ) => {
const { getEditedEntityRecord, canUser, getCurrentTheme } =
select( coreDataStore );

const _availableTemplates = getCurrentTheme()?.is_block_theme
? null
: select( editorStore ).getEditorSettings()
.availableTemplates ?? {};

const extra = {};
const ids = {};

// Other entities the current post type needs merged into its form.
for ( const [ key, entity ] of Object.entries(
ENTITIES[ postType ] ?? {}
) ) {
if (
! canUser( 'read', {
kind: entity.kind,
name: entity.name,
} )
) {
continue;
}
const id = entity.getId ? entity.getId( select ) : undefined;
// Entities resolved through another record need a valid id.
if ( entity.getId && ! id ) {
continue;
}
extra[ key ] = getEditedEntityRecord(
entity.kind,
entity.name,
id
);
ids[ key ] = id;
}

return {
entityData: extra,
entityIds: ids,
availableTemplates: _availableTemplates,
};
},
[ postType ]
);

// Augment record only when needed(not a block theme with available templates).
const augmentedRecord = useMemo( () => {
if ( ! record || ! availableTemplates ) {
// Merge the supplementary data onto the record only when there is any.
const data = useMemo( () => {
if ( ! record ) {
return record;
}
return {
...record,
available_templates: availableTemplates,
};
}, [ record, availableTemplates ] );
const extra = { ...entityData };
if ( availableTemplates && Object.keys( availableTemplates ).length ) {
extra.available_templates = availableTemplates;
}
if ( ! Object.keys( extra ).length ) {
return record;
}
return { ...record, ...extra };
}, [ record, entityData, availableTemplates ] );

const { editEntityRecord } = useDispatch( coreDataStore );

// Map of namespaced field id to the namespace key its entity is merged under.
const fieldNamespaces = useMemo( () => {
const map = {};
for ( const [ namespace, entity ] of Object.entries(
ENTITIES[ postType ] ?? {}
) ) {
for ( const id of entity.fields ?? [] ) {
map[ id ] = namespace;
}
}
return map;
}, [ postType ] );

const _fields = usePostFields( { postType } );
const fields = useMemo(
() =>
_fields
?.map( ( field ) => {
const namespace = fieldNamespaces[ field.id ];
if ( namespace ) {
return bindFieldToNamespace(
field,
namespace,
ENTITIES[ postType ]?.[ namespace ]?.isVisible
);
}
if ( field.id === 'status' ) {
return {
...field,
Expand Down Expand Up @@ -112,23 +247,55 @@ export default function DataFormPostSummary( { onActionPerformed } ) {
// Editor-only field, injected here rather than registered
// so it never leaks into the site editor list / quick-edit fields.
.concat( revisionsField ),
[ _fields, templatePanelMode, availableTemplates ]
[
_fields,
templatePanelMode,
availableTemplates,
fieldNamespaces,
postType,
]
);

const onChange = ( edits ) => {
// Route edits that target another entity (merged in under a namespace)
// back to that entity; collect the rest for the post being edited.
const entities = ENTITIES[ postType ] ?? {};
const baseEdits = {};
for ( const [ key, value ] of Object.entries( edits ) ) {
const entity = entities[ key ];
if ( entity ) {
editEntityRecord(
entity.kind,
entity.name,
entityIds[ key ],
value
);
} else {
baseEdits[ key ] = value;
}
}

if ( ! Object.keys( baseEdits ).length ) {
return;
}

if (
edits.status &&
edits.status !== 'future' &&
baseEdits.status &&
baseEdits.status !== 'future' &&
record?.status === 'future' &&
new Date( record.date ) > new Date()
) {
edits.date = null;
baseEdits.date = null;
}
if ( edits.status && edits.status === 'private' && record?.password ) {
edits.password = '';
if (
baseEdits.status &&
baseEdits.status === 'private' &&
record?.password
) {
baseEdits.password = '';
}

editEntityRecord( 'postType', postType, postId, edits );
editEntityRecord( 'postType', postType, postId, baseEdits );
};
return (
<PostPanelSection className="editor-post-summary">
Expand All @@ -139,7 +306,7 @@ export default function DataFormPostSummary( { onActionPerformed } ) {
onActionPerformed={ onActionPerformed }
/>
<DataForm
data={ augmentedRecord }
data={ data }
fields={ fields }
form={ form }
onChange={ onChange }
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/components/sidebar/post-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function PostSummary( { onActionPerformed } ) {
);
if (
window?.__experimentalDataFormInspector &&
[ 'page', 'post' ].includes( postType )
[ 'page', 'post', 'wp_template' ].includes( postType )
) {
return <DataFormPostSummary onActionPerformed={ onActionPerformed } />;
}
Expand Down
Loading
Loading