Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Site Editor: fix template for page-on-front option #66739

Merged
merged 3 commits into from
Nov 5, 2024
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,32 @@ function useResolveEditedEntityAndContext( { postId, postType } ) {
postTypeToResolve === 'page' &&
homepageId === postIdToResolve
) {
return getDefaultTemplateId( { slug: 'front-page' } );
// The /lookup endpoint cannot currently handle a lookup
// when a page is set as the front page, so specifically in
// that case, we want to check if there is a front page
// template, and instead of falling back to the home
// template, we want to fall back to the page template.
const templates = getEntityRecords(
'postType',
TEMPLATE_POST_TYPE,
{
per_page: -1,
}
);
if ( templates ) {
const id = templates?.find(
( { slug } ) => slug === 'front-page'
)?.id;
if ( id ) {
return id;
}

// If not front page template is found, continue with
// the logic below (fetching the page template).
} else {
// Still resolving `templates`.
return undefined;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

See https://github.com/WordPress/gutenberg/pull/66579/files#diff-90ac1a8edea4ffca3eb4acd2bc2aeed05d54392fc843eb1f253403ae66771dceL59-L66, which has the same logic, but spread over three different pieces: two in the first selector, and one in the second. I put them all together here.

}

const editedEntity = getEditedEntityRecord(
Expand Down
Loading