Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions packages/block-library/src/template-part/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ export const init = () => {
'blockEditor.__unstableCanInsertBlockType',
'removeTemplatePartsFromPostTemplates',
(
can,
canInsert,
blockType,
rootClientId,
{ getBlock, getBlockParentsByBlockName }
) => {
if ( blockType.name !== 'core/template-part' ) {
return can;
return canInsert;
}

for ( const disallowedParentType of DISALLOWED_PARENTS ) {
Expand Down
36 changes: 20 additions & 16 deletions packages/edit-post/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,6 @@ export function initializeEditor(
settings,
initialEdits
) {
// Prevent adding template part in the post editor.
// Only add the filter when the post editor is initialized, not imported.
addFilter(
'blockEditor.__unstableCanInsertBlockType',
'removeTemplatePartsFromInserter',
( can, blockType ) => {
if (
! select( editPostStore ).isEditingTemplate() &&
blockType.name === 'core/template-part'
) {
return false;
}
return can;
}
);

const target = document.getElementById( id );
const reboot = reinitializeEditor.bind(
null,
Expand Down Expand Up @@ -137,6 +121,26 @@ export function initializeEditor(
} );
}

/*
* Prevent adding template part in the post editor.
* Only add the filter when the post editor is initialized, not imported.
* Also only add the filter(s) after registerCoreBlocks()
* so that common filters in the block library are not overwritten.
*/
addFilter(
'blockEditor.__unstableCanInsertBlockType',
'removeTemplatePartsFromInserter',
( canInsert, blockType ) => {
if (
! select( editPostStore ).isEditingTemplate() &&
blockType.name === 'core/template-part'
) {
return false;
}
return canInsert;
}
);

// Show a console log warning if the browser is not in Standards rendering mode.
const documentMode =
document.compatMode === 'CSS1Compat' ? 'Standards' : 'Quirks';
Expand Down