Skip to content

Commit

Permalink
Decouple Post Blocks Experiment from Site Editor Experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed Dec 18, 2020
1 parent 66496e5 commit 7b6db89
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 28 deletions.
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' );
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
54 changes: 27 additions & 27 deletions packages/block-library/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export const registerCoreBlocks = (
* Function to register experimental core blocks depending on editor settings.
*
* @param {boolean} enableFSEBlocks Whether to enable the full site editing blocks.
* @param {boolean} enablePostBlocks Whether to enable the post blocks.
* @example
* ```js
* import { __experimentalRegisterExperimentalCoreBlocks } from '@wordpress/block-library';
Expand All @@ -200,38 +201,37 @@ export const registerCoreBlocks = (
*/
export const __experimentalRegisterExperimentalCoreBlocks =
process.env.GUTENBERG_PHASE === 2
? ( enableFSEBlocks ) => {
? ( enableFSEBlocks, enablePostBlocks ) => {
const postBlocks = [
siteLogo,
siteTagline,
siteTitle,
query,
queryLoop,
queryPagination,
postTitle,
postContent,
postAuthor,
postComment,
postCommentAuthor,
postCommentContent,
postCommentDate,
postComments,
postCommentsCount,
postCommentsForm,
postDate,
postExcerpt,
postFeaturedImage,
postHierarchicalTerms,
postTags,
];
[
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,
]
: [] ),
? [ templatePart, ...postBlocks ]
: ( enablePostBlocks && postBlocks ) || [] ),
].forEach( registerBlock );
}
: undefined;
7 changes: 6 additions & 1 deletion packages/edit-post/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,13 @@ export function initializeEditor(
);
registerCoreBlocks();
if ( process.env.GUTENBERG_PHASE === 2 ) {
const {
__unstableEnableFullSiteEditingBlocks,
__unstableEnablePostBlocks,
} = settings;
__experimentalRegisterExperimentalCoreBlocks(
settings.__unstableEnableFullSiteEditingBlocks
__unstableEnableFullSiteEditingBlocks,
__unstableEnablePostBlocks
);
}

Expand Down

0 comments on commit 7b6db89

Please sign in to comment.