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

Load the entities list using the view context #37685

Merged
merged 1 commit into from
Jan 17, 2022
Merged
Changes from all commits
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
8 changes: 4 additions & 4 deletions packages/core-data/src/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export const prePersistPostType = ( persistedRecord, edits ) => {
* @return {Promise} Entities promise
*/
async function loadPostTypeEntities() {
const postTypes = await apiFetch( { path: '/wp/v2/types?context=edit' } );
const postTypes = await apiFetch( { path: '/wp/v2/types?context=view' } );
return map( postTypes, ( postType, name ) => {
const isTemplate = [ 'wp_template', 'wp_template_part' ].includes(
name
Expand All @@ -216,7 +216,7 @@ async function loadPostTypeEntities() {
baseURL: `/${ namespace }/${ postType.rest_base }`,
baseURLParams: { context: 'edit' },
name,
label: postType.labels.singular_name,
label: postType.name,
Copy link
Contributor

Choose a reason for hiding this comment

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

This change is going to be difficult to test and the results could be unexpected (although likely relatively minor).

Ideally we would modify the Types API endpoint to provide access to the singular label as that will avoid this change cause knock on effects to UI labels (some of which may be handled in 3rd party plugins).

transientEdits: {
blocks: true,
selection: true,
Expand All @@ -240,7 +240,7 @@ async function loadPostTypeEntities() {
*/
async function loadTaxonomyEntities() {
const taxonomies = await apiFetch( {
path: '/wp/v2/taxonomies?context=edit',
path: '/wp/v2/taxonomies?context=view',
} );
return map( taxonomies, ( taxonomy, name ) => {
const namespace = taxonomy?.rest_namespace ?? 'wp/v2';
Expand All @@ -249,7 +249,7 @@ async function loadTaxonomyEntities() {
baseURL: `/${ namespace }/${ taxonomy.rest_base }`,
baseURLParams: { context: 'edit' },
name,
label: taxonomy.labels.singular_name,
label: taxonomy.name,
};
} );
}
Expand Down