Skip to content
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
3 changes: 3 additions & 0 deletions backport-changelog/7.1/12416.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/12416

* https://github.com/WordPress/gutenberg/pull/79894
36 changes: 0 additions & 36 deletions lib/compat/wordpress-7.1/classic-block.php

This file was deleted.

1 change: 0 additions & 1 deletion lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/compat/wordpress-7.1/kses.php';
require __DIR__ . '/compat/wordpress-7.1/media.php';
require __DIR__ . '/compat/wordpress-7.1/preload.php';
require __DIR__ . '/compat/wordpress-7.1/classic-block.php';
require __DIR__ . '/compat/wordpress-7.1/icons.php';

// Experimental features.
Expand Down
33 changes: 33 additions & 0 deletions packages/block-library/src/freeform/convert-to-blocks-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { ToolbarButton } from '@wordpress/components';
import { useDispatch, useSelect } from '@wordpress/data';
import { rawHandler, serialize } from '@wordpress/blocks';
import { store as blockEditorStore } from '@wordpress/block-editor';

const ConvertToBlocksButton = ( { clientId } ) => {
const { replaceBlocks } = useDispatch( blockEditorStore );
const block = useSelect(
( select ) => {
return select( blockEditorStore ).getBlock( clientId );
},
[ clientId ]
);

return (
<ToolbarButton
onClick={ () =>
replaceBlocks(
block.clientId,
rawHandler( { HTML: serialize( block ) } )
)
}
>
{ __( 'Convert to blocks' ) }
</ToolbarButton>
);
};

export default ConvertToBlocksButton;
32 changes: 11 additions & 21 deletions packages/block-library/src/freeform/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
useBlockProps,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { useDispatch, useSelect } from '@wordpress/data';
import { useSelect } from '@wordpress/data';
import {
Button,
Placeholder,
Expand All @@ -21,14 +21,13 @@ import { classic } from '@wordpress/icons';
/**
* Internal dependencies
*/
import MigrationNotice from './migration-notice';
import ConvertToBlocksButton from './convert-to-blocks-button';
import ModalEdit from './modal';

export default function FreeformEdit( {
attributes,
setAttributes,
clientId,
onReplace,
} ) {
const { content } = attributes;
const [ isOpen, setOpen ] = useState( false );
Expand All @@ -38,10 +37,16 @@ export default function FreeformEdit( {
( select ) => select( blockEditorStore ).canRemoveBlock( clientId ),
[ clientId ]
);
const { removeBlock } = useDispatch( blockEditorStore );

return (
<>
{ canRemove && (
<BlockControls>
<ToolbarGroup>
<ConvertToBlocksButton clientId={ clientId } />
</ToolbarGroup>
</BlockControls>
) }
<BlockControls>
<ToolbarGroup>
<ToolbarButton
Expand All @@ -53,34 +58,19 @@ export default function FreeformEdit( {
</ToolbarGroup>
</BlockControls>
<div { ...useBlockProps() }>
{ canRemove && content && (
<MigrationNotice
content={ content }
onReplace={ onReplace }
/>
) }
{ content ? (
<RawHTML>{ content }</RawHTML>
) : (
<Placeholder
icon={ <BlockIcon icon={ classic } /> }
label={ __( 'Classic' ) }
instructions={ __(
'The Classic block is being phased out. It’s recommended to use other blocks for the best editing experience.'
'Use the classic editor to add content.'
) }
>
{ canRemove && (
<Button
__next40pxDefaultSize
variant="primary"
onClick={ () => removeBlock( clientId ) }
>
{ __( 'Remove block' ) }
</Button>
) }
<Button
__next40pxDefaultSize
variant={ canRemove ? 'secondary' : 'primary' }
variant="primary"
onClick={ () => setOpen( true ) }
>
{ __( 'Edit contents' ) }
Expand Down
10 changes: 1 addition & 9 deletions packages/block-library/src/freeform/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,4 @@ export const settings = {
save,
};

export const init = () => {
// Only expose the block in the inserter if the current post actually needs
// a classic block.
const supports = {
...metadata.supports,
inserter: !! window?.__needsClassicBlock,
};
return initBlock( { name, metadata, settings: { ...settings, supports } } );
};
export const init = () => initBlock( { name, metadata, settings } );
49 changes: 0 additions & 49 deletions packages/block-library/src/freeform/migration-notice.js

This file was deleted.

2 changes: 0 additions & 2 deletions packages/block-library/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,6 @@ const getAllBlocks = () => {
blocks.push( playlistTrack );
}

// Always register the classic block. Inserter availability is controlled
// by the block's `supports.inserter` value in `freeform/init`.
blocks.push( classic );

return blocks.filter( Boolean );
Expand Down
67 changes: 0 additions & 67 deletions phpunit/script-loader-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,71 +76,4 @@ public function test_should_enqueue_stored_styles() {
'Registered styles with handle of "wp-style-engine-my-styles" do not match expected value from the Style Engine store.'
);
}

/**
* Tests that the Classic block is hidden from the inserter by default.
*
* @covers ::wp_declare_classic_block_necessary
*/
public function test_wp_declare_classic_block_necessary_does_nothing_by_default() {
wp_register_script( 'wp-block-library', 'https://example.org/wp-block-library.js' );

wp_declare_classic_block_necessary();

$this->assertFalse(
wp_scripts()->get_data( 'wp-block-library', 'before' ),
'No inline script should be enqueued when the filter is not used.'
);
}

/**
* Tests that the Classic block can be opted into the inserter via the filter.
*
* @covers ::wp_declare_classic_block_necessary
*/
public function test_wp_declare_classic_block_necessary_enqueues_flag_when_filter_enabled() {
wp_register_script( 'wp-block-library', 'https://example.org/wp-block-library.js' );
add_filter( 'wp_classic_block_supports_inserter', '__return_true' );

wp_declare_classic_block_necessary();

$before = wp_scripts()->get_data( 'wp-block-library', 'before' );
$this->assertIsArray(
$before,
'An inline script should be enqueued when the filter opts in.'
);
$this->assertContains(
'window.__needsClassicBlock = true;',
$before,
'The Classic block flag should be added to the wp-block-library inline scripts.'
);
}

/**
* Tests that the current post is passed to the filter.
*
* @covers ::wp_declare_classic_block_necessary
*/
public function test_wp_declare_classic_block_necessary_passes_post_to_filter() {
wp_register_script( 'wp-block-library', 'https://example.org/wp-block-library.js' );

$post_id = self::factory()->post->create();
$GLOBALS['post'] = get_post( $post_id );

$filter_post = false;
add_filter(
'wp_classic_block_supports_inserter',
static function ( $supports_inserter, $post ) use ( &$filter_post ) {
$filter_post = $post;
return $supports_inserter;
},
10,
2
);

wp_declare_classic_block_necessary();

$this->assertInstanceOf( WP_Post::class, $filter_post, 'The post should be passed to the filter.' );
$this->assertSame( $post_id, $filter_post->ID, 'The current post should be passed to the filter.' );
}
}
8 changes: 2 additions & 6 deletions test/e2e/specs/editor/blocks/classic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ test.describe( 'Classic', () => {
.poll( editor.getEditedPostContent )
.toMatch( /\[gallery ids=\"\d+\"\]/ );

await editor.canvas
.getByRole( 'button', { name: 'Convert to blocks' } )
.click();
await editor.clickBlockToolbarButton( 'Convert to blocks' );
const galleryBlock = editor.canvas.getByRole( 'document', {
name: 'Block: Gallery',
} );
Expand All @@ -104,9 +102,7 @@ test.describe( 'Classic', () => {
.poll( editor.getEditedPostContent )
.toMatch( /\[gallery ids=\"\d+\"\]/ );

await editor.canvas
.getByRole( 'button', { name: 'Convert to blocks' } )
.click();
await editor.clickBlockToolbarButton( 'Convert to blocks' );
await expect
.poll( editor.getEditedPostContent )
.toMatch( /<!-- wp:gallery/ );
Expand Down
Loading