Skip to content

Commit

Permalink
Quote: add support for nested blocks (#25892)
Browse files Browse the repository at this point in the history
Implements nested blocks support for Quotes. This allows the display of lists, headings, images, and virtually any other block within a blockquote.

Co-authored-by: Ella van Durpe <ella@vandurpe.com>
Co-authored-by: André <583546+oandregal@users.noreply.github.com>
  • Loading branch information
oandregal and ellatrix committed Jul 15, 2022
1 parent 4063556 commit d70856b
Show file tree
Hide file tree
Showing 53 changed files with 708 additions and 1,338 deletions.
4 changes: 2 additions & 2 deletions lib/experimental/block-editor-settings-mobile.php
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
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
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
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
Expand Up @@ -65,19 +65,6 @@ const transforms = {
} );
},
},
{
type: 'block',
blocks: [ 'core/quote', 'core/pullquote' ],
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

0 comments on commit d70856b

Please sign in to comment.