diff --git a/packages/edit-site/src/store/selectors.js b/packages/edit-site/src/store/selectors.js index 3980d08bbc27be..6d0996a5e939d3 100644 --- a/packages/edit-site/src/store/selectors.js +++ b/packages/edit-site/src/store/selectors.js @@ -243,11 +243,20 @@ export function isSaveViewOpened( state ) { /** * Returns the template parts and their blocks for the current edited template. * + * @deprecated * @param {Object} state Global application state. * @return {Array} Template parts and their blocks in an array. */ export const getCurrentTemplateTemplateParts = createRegistrySelector( ( select ) => () => { + deprecated( + `select( 'core/edit-site' ).getCurrentTemplateTemplateParts()`, + { + since: '6.7', + version: '6.9', + alternative: `select( 'core/block-editor' ).getBlocksByName( 'core/template-part' )`, + } + ); return unlock( select( editorStore ) ).getCurrentTemplateTemplateParts(); diff --git a/packages/editor/src/store/private-selectors.js b/packages/editor/src/store/private-selectors.js index c635cbc816f92b..3da3621dab2adf 100644 --- a/packages/editor/src/store/private-selectors.js +++ b/packages/editor/src/store/private-selectors.js @@ -26,6 +26,8 @@ import { __experimentalGetDefaultTemplatePartAreas, } from './selectors'; import { getEntityActions as _getEntityActions } from '../dataviews/store/private-selectors'; +import { getFilteredTemplatePartBlocks } from './utils/get-filtered-template-parts'; +import { TEMPLATE_PART_POST_TYPE } from './constants'; const EMPTY_INSERTION_POINT = { rootClientId: undefined, @@ -160,3 +162,30 @@ export const hasPostMetaChanges = createRegistrySelector( export function getEntityActions( state, ...args ) { return _getEntityActions( state.dataviews, ...args ); } + +/** + * Returns the template parts and their blocks for the current edited template. + * This selector is deprecated and not used on the codebase, was just kept because + * it is called inside select( 'core/edit-site' ).getCurrentTemplateTemplateParts() + * which is also deprecated. + * + * @deprecated + * @param {Object} state Global application state. + * @return {Array} Template parts and their blocks in an array. + */ +export const getCurrentTemplateTemplateParts = createRegistrySelector( + ( select ) => () => { + const templateParts = select( coreStore ).getEntityRecords( + 'postType', + TEMPLATE_PART_POST_TYPE, + { per_page: -1 } + ); + + const clientIds = + select( blockEditorStore ).getBlocksByName( 'core/template-part' ); + const blocks = + select( blockEditorStore ).getBlocksByClientId( clientIds ); + + return getFilteredTemplatePartBlocks( blocks, templateParts ); + } +);