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

Template/site editor: prevent classic block from loading #27059

Closed
wants to merge 3 commits into from
Closed
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
7 changes: 5 additions & 2 deletions packages/block-library/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ import * as postFeaturedImage from './post-featured-image';
import * as postHierarchicalTerms from './post-hierarchical-terms';
import * as postTags from './post-tags';

const isClassicEnabled =
window.wpEditorL10n && window.wp && window.wp.oldEditor;

Comment on lines +90 to +92
Copy link
Member

Choose a reason for hiding this comment

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

These values might change during runtime so a function would work better here. This would fix the tests too.

Suggested change
const isClassicEnabled =
window.wpEditorL10n && window.wp && window.wp.oldEditor;
const isClassicEnabled = () =>
window.wpEditorL10n && window.wp && window.wp.oldEditor;

/**
* Function to register an individual block.
*
Expand Down Expand Up @@ -139,7 +142,7 @@ export const __experimentalGetCoreBlocks = () => [
embed,
file,
group,
window.wp && window.wp.oldEditor ? classic : null, // Only add the classic block in WP Context
isClassicEnabled ? classic : null, // Only add the classic block in WP Context
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
isClassicEnabled ? classic : null, // Only add the classic block in WP Context
isClassicEnabled() ? classic : null, // Only add the classic block in WP Context

html,
mediaText,
latestComments,
Expand Down Expand Up @@ -182,7 +185,7 @@ export const registerCoreBlocks = (
blocks.forEach( registerBlock );

setDefaultBlockName( paragraph.name );
if ( window.wp && window.wp.oldEditor ) {
if ( isClassicEnabled ) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if ( isClassicEnabled ) {
if ( isClassicEnabled() ) {

setFreeformContentHandlerName( classic.name );
}
setUnregisteredTypeHandlerName( missing.name );
Expand Down
31 changes: 19 additions & 12 deletions packages/block-library/src/missing/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,25 @@ function MissingBlockWarning( { attributes, convertToHTML } ) {
const actions = [];
let messageHTML;
if ( hasContent && hasHTMLBlock ) {
messageHTML = sprintf(
/* translators: %s: block name */
__(
'Your site doesn’t include support for the "%s" block. You can leave this block intact, convert its content to a Custom HTML block, or remove it entirely.'
),
originalName
);
actions.push(
<Button key="convert" onClick={ convertToHTML } isPrimary>
{ __( 'Keep as HTML' ) }
</Button>
);
if ( originalName ) {
messageHTML = sprintf(
/* translators: %s: block name */
__(
'Your site doesn’t include support for the "%s" block. You can leave this block intact, convert its content to a Custom HTML block, or remove it entirely.'
),
originalName
);

actions.push(
<Button key="convert" onClick={ convertToHTML } isPrimary>
{ __( 'Keep as HTML' ) }
</Button>
);
} else {
messageHTML = __(
'Legacy content cannot be edited in this context.'
);
}
} else {
messageHTML = sprintf(
/* translators: %s: block name */
Expand Down
1 change: 1 addition & 0 deletions test/unit/__mocks__/@wordpress/block-library.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Make sure the classic block is registered.
window.wp = window.wp || {};
window.wp.oldEditor = {};
window.wpEditorL10n = {};

export * from '../../../../packages/block-library/src';