-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Template activation: improve back compat #72223
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
Changes from 17 commits
18797bb
115d1ad
3ab2657
fd6350c
2532335
3c33645
8d46498
c166ecb
47e3511
5db3f6c
6668287
d53b1c8
2945540
5ebb1f5
d405e56
a2cb82b
272ac55
cd074ae
a6e06b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -323,8 +323,20 @@ export const deleteEntityRecord = | |
| } ); | ||
|
|
||
| let hasError = false; | ||
| let { baseURL } = entityConfig; | ||
| if ( | ||
| kind === 'postType' && | ||
| name === 'wp_template' && | ||
| recordId && | ||
| typeof recordId === 'string' && | ||
| ! /^\d+$/.test( recordId ) | ||
| ) { | ||
| baseURL = | ||
| baseURL.slice( 0, baseURL.lastIndexOf( '/' ) ) + | ||
| '/templates'; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about moving this to the entity config, but that's only called once on init so it's not possible to have a dynamic baseURL without creating a new API, so I think it might be better left here.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Worth encapsulating as a function of |
||
| } | ||
| try { | ||
| let path = `${ entityConfig.baseURL }/${ recordId }`; | ||
| let path = `${ baseURL }/${ recordId }`; | ||
|
|
||
| if ( query ) { | ||
| path = addQueryArgs( path, query ); | ||
|
|
@@ -521,46 +533,6 @@ export const saveEntityRecord = | |
| const entityIdKey = entityConfig.key || DEFAULT_ENTITY_KEY; | ||
| const recordId = record[ entityIdKey ]; | ||
|
|
||
| // When called with a theme template ID, trigger the compatibility | ||
| // logic. | ||
| if ( | ||
| kind === 'postType' && | ||
| name === 'wp_template' && | ||
| typeof recordId === 'string' && | ||
| ! /^\d+$/.test( recordId ) | ||
| ) { | ||
| // Get the theme template. | ||
| const template = await select.getEntityRecord( | ||
| 'postType', | ||
| 'wp_registered_template', | ||
| recordId | ||
| ); | ||
| // Duplicate the theme template and make the edit. | ||
| const newTemplate = await dispatch.saveEntityRecord( | ||
| 'postType', | ||
| 'wp_template', | ||
| { | ||
| ...template, | ||
| ...record, | ||
| id: undefined, | ||
| type: 'wp_template', | ||
| status: 'publish', | ||
| } | ||
| ); | ||
| // Make the new template active. | ||
| const activeTemplates = await select.getEntityRecord( | ||
| 'root', | ||
| 'site' | ||
| ); | ||
| await dispatch.saveEntityRecord( 'root', 'site', { | ||
| active_templates: { | ||
| ...activeTemplates.active_templates, | ||
| [ newTemplate.slug ]: newTemplate.id, | ||
| }, | ||
| } ); | ||
| return newTemplate; | ||
| } | ||
|
|
||
| const lock = await dispatch.__unstableAcquireStoreLock( | ||
| STORE_NAME, | ||
| [ 'entities', 'records', kind, name, recordId || uuid() ], | ||
|
|
@@ -598,10 +570,21 @@ export const saveEntityRecord = | |
| let updatedRecord; | ||
| let error; | ||
| let hasError = false; | ||
| let { baseURL } = entityConfig; | ||
| // For "string" IDs, use the old templates endpoint. | ||
| if ( | ||
| kind === 'postType' && | ||
| name === 'wp_template' && | ||
| recordId && | ||
| typeof recordId === 'string' && | ||
| ! /^\d+$/.test( recordId ) | ||
| ) { | ||
| baseURL = | ||
| baseURL.slice( 0, baseURL.lastIndexOf( '/' ) ) + | ||
| '/templates'; | ||
| } | ||
| try { | ||
| const path = `${ entityConfig.baseURL }${ | ||
| recordId ? '/' + recordId : '' | ||
| }`; | ||
| const path = `${ baseURL }${ recordId ? '/' + recordId : '' }`; | ||
| const persistedRecord = select.getRawEntityRecord( | ||
| kind, | ||
| name, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.