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

Quote: use nested blocks #25892

Merged
merged 4 commits into from
Jul 15, 2022
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 lib/experimental/block-editor-settings-mobile.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ function gutenberg_get_block_editor_settings_mobile( $settings ) {
$settings['__experimentalStyles'] = gutenberg_get_global_styles();
}

// To be set to true when the web makes quote v2 (inner blocks) the default.
// To tell mobile that the site uses quote v2 (inner blocks).
// See https://github.com/WordPress/gutenberg/pull/25892.
$settings['__experimentalEnableQuoteBlockV2'] = gutenberg_is_quote_v2_enabled();
$settings['__experimentalEnableQuoteBlockV2'] = true;
}

return $settings;
Expand Down
13 changes: 0 additions & 13 deletions lib/experimental/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,13 @@
* @package gutenberg
*/

/**
* Returns whether the quote v2 is enabled by the user.
*
* @return boolean
*/
function gutenberg_is_quote_v2_enabled() {
return get_option( 'gutenberg-experiments' ) && array_key_exists( 'gutenberg-quote-v2', get_option( 'gutenberg-experiments' ) );
}

/**
* Sets a global JS variable used to trigger the availability of the experimental blocks.
*/
function gutenberg_enable_experimental_blocks() {
if ( get_option( 'gutenberg-experiments' ) && array_key_exists( 'gutenberg-list-v2', get_option( 'gutenberg-experiments' ) ) ) {
wp_add_inline_script( 'wp-block-library', 'window.__experimentalEnableListBlockV2 = true', 'before' );
}

if ( gutenberg_is_quote_v2_enabled() ) {
wp_add_inline_script( 'wp-block-library', 'window.__experimentalEnableQuoteBlockV2 = true', 'before' );
}
}

add_action( 'admin_init', 'gutenberg_enable_experimental_blocks' );
11 changes: 0 additions & 11 deletions lib/experiments-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,6 @@ function gutenberg_initialize_experiments_settings() {
'id' => 'gutenberg-list-v2',
)
);
add_settings_field(
'gutenberg-quote-v2',
__( 'Quote block v2', 'gutenberg' ),
'gutenberg_display_experiment_field',
'gutenberg-experiments',
'gutenberg_experiments_section',
array(
'label' => __( 'Test a new quote block that allows nested blocks (Warning: The new block is not ready. You may experience content loss, avoid using it on production sites)', 'gutenberg' ),
'id' => 'gutenberg-quote-v2',
)
);
register_setting(
'gutenberg-experiments',
'gutenberg-experiments'
Expand Down
13 changes: 2 additions & 11 deletions packages/block-library/src/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,6 @@ const devOnly = ( block ) => ( !! __DEV__ ? block : null );
const iOSOnly = ( block ) =>
Platform.OS === 'ios' ? block : devOnly( block );

// To be removed once Quote V2 is released on the web editor.
function quoteCheck( quoteBlock, blocksFlags ) {
if ( blocksFlags?.__experimentalEnableQuoteBlockV2 ) {
quoteBlock.settings = quoteBlock?.settingsV2;
}
return quoteBlock;
}

// Hide the Classic block and SocialLink block
addFilter(
'blocks.registerBlockType',
Expand Down Expand Up @@ -238,10 +230,9 @@ addFilter(
*
* registerCoreBlocks();
* ```
* @param {Object} [blocksFlags] Experimental flags
*
*/
export const registerCoreBlocks = ( blocksFlags ) => {
export const registerCoreBlocks = () => {
// When adding new blocks to this list please also consider updating /src/block-support/supported-blocks.json in the Gutenberg-Mobile repo
[
paragraph,
Expand All @@ -254,7 +245,7 @@ export const registerCoreBlocks = ( blocksFlags ) => {
nextpage,
separator,
list,
quoteCheck( quote, blocksFlags ),
quote,
mediaText,
preformatted,
gallery,
Expand Down
30 changes: 0 additions & 30 deletions packages/block-library/src/list/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,6 @@ const transforms = {
} );
},
},
{
type: 'block',
blocks: [ 'core/quote', 'core/pullquote' ],
Copy link
Member

@ellatrix ellatrix Feb 9, 2022

Choose a reason for hiding this comment

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

No need to handled this anymore. The quote block now has a wildcard transform which includes wrapping a list into a quote. Similarly for reverse direction, it no longer makes sense to transform a quote into a list because it can be mixed content.

transform: ( { value, anchor } ) => {
return createBlock( 'core/list', {
values: toHTMLString( {
value: create( { html: value, multilineTag: 'p' } ),
multilineTag: 'li',
} ),
anchor,
} );
},
},
{
type: 'raw',
selector: 'ol,ul',
Expand Down Expand Up @@ -174,23 +161,6 @@ const transforms = {
} )
),
},
{
type: 'block',
blocks: [ 'core/quote' ],
transform: ( { values, anchor } ) => {
return createBlock( 'core/quote', {
value: toHTMLString( {
value: create( {
html: values,
multilineTag: 'li',
multilineWrapperTags: [ 'ul', 'ol' ],
} ),
multilineTag: 'p',
} ),
anchor,
} );
},
},
{
type: 'block',
blocks: [ 'core/pullquote' ],
Expand Down
Loading