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

Decouple Post Blocks Experiment from Site Editor Experiment #27822

Closed
wants to merge 2 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
2 changes: 2 additions & 0 deletions lib/editor-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function gutenberg_get_common_block_editor_settings() {

$settings = array(
'__unstableEnableFullSiteEditingBlocks' => gutenberg_is_fse_theme(),
'__unstableEnablePostBlocks' => gutenberg_is_experiment_enabled( 'gutenberg-post-blocks' ),
'disableCustomColors' => get_theme_support( 'disable-custom-colors' ),
'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ),
'disableCustomGradients' => get_theme_support( 'disable-custom-gradients' ),
Expand Down Expand Up @@ -77,6 +78,7 @@ function gutenberg_get_common_block_editor_settings() {
*/
function gutenberg_extend_post_editor_settings( $settings ) {
$settings['__unstableEnableFullSiteEditingBlocks'] = gutenberg_is_fse_theme();
$settings['__unstableEnablePostBlocks'] = gutenberg_is_experiment_enabled( 'gutenberg-post-blocks' );
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add || gutenberg_is_fse_theme(). It doesn't make sense for me to have an FSE theme without these blocks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We do add them if gutenberg_is_fse_theme... The only difference in the current status of this PR is template part, which is enabled only in FSE.

return $settings;
}
add_filter( 'block_editor_settings', 'gutenberg_extend_post_editor_settings' );
11 changes: 11 additions & 0 deletions lib/experiments-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ function gutenberg_initialize_experiments_settings() {
'gutenberg_display_experiment_section',
'gutenberg-experiments'
);
add_settings_field(
'gutenberg-post-blocks',
__( 'Post Blocks', 'gutenberg' ),
'gutenberg_display_experiment_field',
'gutenberg-experiments',
'gutenberg_experiments_section',
array(
'label' => __( 'Enable Post Blocks in block editor', 'gutenberg' ),
'id' => 'gutenberg-post-blocks',
)
);
add_settings_field(
'gutenberg-navigation',
__( 'Navigation', 'gutenberg' ),
Expand Down
187 changes: 142 additions & 45 deletions packages/block-library/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ const registerBlock = ( block ) => {
* const coreBlocks = __experimentalGetCoreBlocks();
* ```
*/
// TODO this doesn't need to be a function and check how to remove,
// since `registerCoreBlocks` API has the blocks param...
export const __experimentalGetCoreBlocks = () => [
// Common blocks are grouped at the top to prioritize their display
// in various contexts — like the inserter and auto-complete components.
Expand Down Expand Up @@ -162,6 +164,123 @@ export const __experimentalGetCoreBlocks = () => [
video,
];

const CORE_BLOCKS = [
// Common blocks are grouped at the top to prioritize their display
// in various contexts — like the inserter and auto-complete components.
paragraph,
image,
heading,
gallery,
list,
quote,
// Register all remaining core blocks.
audio,
button,
buttons,
code,
columns,
column,
cover,
embed,
file,
group,
html,
mediaText,
missing,
preformatted,
pullquote,
separator,
socialLinks,
socialLink,
spacer,
subhead,
table,
textColumns,
verse,
video,
];

/**
* Function to register core blocks provided by the block editor.
*/
export const __experimentalRegisterCoreBlocks = () => {
CORE_BLOCKS.forEach( registerBlock );
setDefaultBlockName( paragraph.name );
setUnregisteredTypeHandlerName( missing.name );
setGroupingBlockName( group.name );
};

/**
* Registers WordPress Post Editor specific blocks.
*/
export const __experimentalRegisterWordPressPostEditorBlocks = () => {
const wpPostEditorBlocks = [
archives,
calendar,
categories,
latestComments,
latestPosts,
more,
nextpage,
reusableBlock,
rss,
search,
shortcode,
tagCloud,
];
wpPostEditorBlocks.forEach( registerBlock );
};

/**
* Register classic block only if in WP context.
*/
export const __experimentalRegisterClassicBlock = () => {
if ( ! window.wp?.oldEditor ) return;
registerBlock( classic );
setFreeformContentHandlerName( classic.name );
};

/**
* Register WordPress Full Site Editing blocks.
*
* @param {Object} settings Editor settings object.
* @param {boolean} settings.enableFSEBlocks Whether to enable the full site editing blocks.
* @param {boolean} settings.enablePostBlocks Whether to enable the post blocks.
*/
export const __experimentalRegisterWordPressFullSiteEditingBocks = ( {
enableFSEBlocks,
enablePostBlocks,
} = {} ) => {
if ( process.env.GUTENBERG_PHASE !== 2 ) return;
const postBlocks = [
siteLogo,
siteTagline,
siteTitle,
query,
queryLoop,
queryPagination,
postTitle,
postContent,
postAuthor,
postComment,
postCommentAuthor,
postCommentContent,
postCommentDate,
postComments,
postCommentsCount,
postCommentsForm,
postDate,
postExcerpt,
postFeaturedImage,
postHierarchicalTerms,
postTags,
];
( enableFSEBlocks
? [ templatePart, ...postBlocks ]
: ( enablePostBlocks && postBlocks ) || []
).forEach( registerBlockType );
};

/**
* Function to register core blocks provided by the block editor.
*
Expand All @@ -186,52 +305,30 @@ export const registerCoreBlocks = (
setUnregisteredTypeHandlerName( missing.name );
setGroupingBlockName( group.name );
};
/**
* Function to register experimental core blocks.
*/
// TODO check all usages of this...
export const __experimentalRegisterExperimentalCoreBlocks = () => {
if ( process.env.GUTENBERG_PHASE !== 2 ) return;
[ navigation, navigationLink ].forEach( registerBlock );
};

/**
* Function to register experimental core blocks depending on editor settings.
*
* @param {boolean} enableFSEBlocks Whether to enable the full site editing blocks.
* @example
* ```js
* import { __experimentalRegisterExperimentalCoreBlocks } from '@wordpress/block-library';
* Register all blocks according to editor's settings and
* takes into account `process.env.GUTENBERG_PHASE`.
* - core blocks
* - classic block
* - WP post editor blocks
* - experimental core blocks
* - WP FSE blocks conditionally based on settings.
*
* __experimentalRegisterExperimentalCoreBlocks( settings );
* ```
* @param {Object} settings Editor settings object.
*/
export const __experimentalRegisterExperimentalCoreBlocks =
process.env.GUTENBERG_PHASE === 2
? ( enableFSEBlocks ) => {
[
navigation,
navigationLink,

// Register Full Site Editing Blocks.
...( enableFSEBlocks
? [
siteLogo,
siteTagline,
siteTitle,
templatePart,
query,
queryLoop,
queryPagination,
postTitle,
postContent,
postAuthor,
postComment,
postCommentAuthor,
postCommentContent,
postCommentDate,
postComments,
postCommentsCount,
postCommentsForm,
postDate,
postExcerpt,
postFeaturedImage,
postHierarchicalTerms,
postTags,
]
: [] ),
].forEach( registerBlock );
}
: undefined;
export const __experimentalRegisterAllBlocks = ( settings ) => {
__experimentalRegisterCoreBlocks();
__experimentalRegisterClassicBlock();
__experimentalRegisterWordPressPostEditorBlocks();
__experimentalRegisterExperimentalCoreBlocks();
__experimentalRegisterWordPressFullSiteEditingBocks( settings );
};
11 changes: 2 additions & 9 deletions packages/edit-navigation/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import { map, set, flatten, omit, partialRight } from 'lodash';
/**
* WordPress dependencies
*/
import {
registerCoreBlocks,
__experimentalRegisterExperimentalCoreBlocks,
} from '@wordpress/block-library';
import { __experimentalRegisterAllBlocks } from '@wordpress/block-library';
import { render } from '@wordpress/element';
import { createHigherOrderComponent } from '@wordpress/compose';
import { __ } from '@wordpress/i18n';
Expand Down Expand Up @@ -164,11 +161,7 @@ export function initialize( id, settings ) {
removeNavigationBlockEditUnsupportedFeatures
);

registerCoreBlocks();

if ( process.env.GUTENBERG_PHASE === 2 ) {
__experimentalRegisterExperimentalCoreBlocks();
}
__experimentalRegisterAllBlocks();

settings.__experimentalFetchLinkSuggestions = partialRight(
fetchLinkSuggestions,
Expand Down
13 changes: 3 additions & 10 deletions packages/edit-post/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import '@wordpress/core-data';
import '@wordpress/block-editor';
import '@wordpress/editor';
import {
registerCoreBlocks,
__experimentalRegisterExperimentalCoreBlocks,
} from '@wordpress/block-library';
import { __experimentalRegisterAllBlocks } from '@wordpress/block-library';
import { render, unmountComponentAtNode } from '@wordpress/element';

/**
Expand Down Expand Up @@ -91,12 +88,8 @@ export function initializeEditor(
settings,
initialEdits
);
registerCoreBlocks();
if ( process.env.GUTENBERG_PHASE === 2 ) {
__experimentalRegisterExperimentalCoreBlocks(
settings.__unstableEnableFullSiteEditingBlocks
);
}

__experimentalRegisterAllBlocks( settings );

// Show a console log warning if the browser is not in Standards rendering mode.
const documentMode =
Expand Down
10 changes: 2 additions & 8 deletions packages/edit-site/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import apiFetch from '@wordpress/api-fetch';
import { addQueryArgs } from '@wordpress/url';
import { __ } from '@wordpress/i18n';
import {
registerCoreBlocks,
__experimentalRegisterExperimentalCoreBlocks,
} from '@wordpress/block-library';
import { __experimentalRegisterAllBlocks } from '@wordpress/block-library';
import { render } from '@wordpress/element';

/**
Expand Down Expand Up @@ -58,10 +55,7 @@ export function initialize( id, settings ) {

registerEditSiteStore( { settings } );

registerCoreBlocks();
if ( process.env.GUTENBERG_PHASE === 2 ) {
__experimentalRegisterExperimentalCoreBlocks( true );
}
__experimentalRegisterAllBlocks( { enableFSEBlocks: true } );

render( <Editor />, document.getElementById( id ) );
}
Expand Down
17 changes: 4 additions & 13 deletions packages/edit-widgets/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
*/
import {
registerBlockType,
unregisterBlockType,
unstable__bootstrapServerSideBlockDefinitions, // eslint-disable-line camelcase
} from '@wordpress/blocks';
import { render } from '@wordpress/element';
import {
registerCoreBlocks,
__experimentalGetCoreBlocks,
__experimentalRegisterExperimentalCoreBlocks,
} from '@wordpress/block-library';
import { __experimentalRegisterAllBlocks } from '@wordpress/block-library';

/**
* Internal dependencies
Expand All @@ -28,14 +25,8 @@ import Layout from './components/layout';
* @param {Object} settings Block editor settings.
*/
export function initialize( id, settings ) {
const coreBlocks = __experimentalGetCoreBlocks().filter(
( block ) => ! [ 'core/more' ].includes( block.name )
);
registerCoreBlocks( coreBlocks );

if ( process.env.GUTENBERG_PHASE === 2 ) {
__experimentalRegisterExperimentalCoreBlocks();
}
__experimentalRegisterAllBlocks();
unregisterBlockType( 'core/more' );
registerBlock( createLegacyWidget( settings ) );
registerBlock( widgetArea );
render(
Expand Down
10 changes: 2 additions & 8 deletions test/integration/full-content/full-content.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ import {
unstable__bootstrapServerSideBlockDefinitions, // eslint-disable-line camelcase
} from '@wordpress/blocks';
import { parse as grammarParse } from '@wordpress/block-serialization-default-parser';
import {
registerCoreBlocks,
__experimentalRegisterExperimentalCoreBlocks,
} from '@wordpress/block-library';
import { __experimentalRegisterAllBlocks } from '@wordpress/block-library';
//eslint-disable-next-line no-restricted-syntax
import {
blockNameToFixtureBasename,
Expand Down Expand Up @@ -67,10 +64,7 @@ describe( 'full post content fixture', () => {
unstable__bootstrapServerSideBlockDefinitions( blockDefinitions );
// Load all hooks that modify blocks
require( '../../../packages/editor/src/hooks' );
registerCoreBlocks();
if ( process.env.GUTENBERG_PHASE === 2 ) {
__experimentalRegisterExperimentalCoreBlocks( true );
}
__experimentalRegisterAllBlocks( { enableFSEBlocks: true } );
} );

blockBasenames.forEach( ( basename ) => {
Expand Down