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

Fix template display in page details with a custom template #51638

Merged
merged 2 commits into from
Jun 19, 2023
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 @@ -11,7 +11,11 @@ import {
import { count as wordCount } from '@wordpress/wordcount';
import { useSelect } from '@wordpress/data';
import { decodeEntities } from '@wordpress/html-entities';
import { store as coreStore, useEntityRecord } from '@wordpress/core-data';
import {
store as coreStore,
useEntityRecord,
useEntityRecords,
} from '@wordpress/core-data';

/**
* Internal dependencies
Expand Down Expand Up @@ -95,13 +99,14 @@ function getPageDetails( page ) {

export default function PageDetails( { id } ) {
const { record } = useEntityRecord( 'postType', 'page', id );

const { records: templates } = useEntityRecords(
'postType',
'wp_template',
{ per_page: -1 }
);
ntsekouras marked this conversation as resolved.
Show resolved Hide resolved
const { parentTitle, templateTitle } = useSelect(
( select ) => {
const { getEditedPostContext, getSettings } = unlock(
select( editSiteStore )
);
const defaultTemplateTypes = getSettings()?.defaultTemplateTypes;
const { getEditedPostContext } = unlock( select( editSiteStore ) );
const postContext = getEditedPostContext();

// Template title.
Expand All @@ -112,10 +117,10 @@ export default function PageDetails( { id } ) {
? postContext?.templateSlug
: null;
const _templateTitle =
defaultTemplateTypes && templateSlug
? defaultTemplateTypes.find(
templates && templateSlug
ntsekouras marked this conversation as resolved.
Show resolved Hide resolved
? templates?.find(
ntsekouras marked this conversation as resolved.
Show resolved Hide resolved
( template ) => template.slug === templateSlug
)?.title
)?.title?.rendered
: null;

// Parent page title.
Expand All @@ -135,7 +140,7 @@ export default function PageDetails( { id } ) {
templateTitle: _templateTitle,
};
},
[ record ]
[ record, templates ]
ntsekouras marked this conversation as resolved.
Show resolved Hide resolved
);
return (
<VStack spacing={ 5 }>
Expand Down