mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Blocks: Align with Gutenberg the name of generated asset handle for core blocks
Related Gutenberg PR: https://github.com/WordPress/gutenberg/pull/25220. It aligns with the latest changes added by aristath to the Gutenberg project. As part of styles splitting for core blocks, there was a special pattern introduced for how style handles are named. Ideally, we would apply it to all blocks but there might be some backward compatibility considerations so I left the handling for non-core blocks unchanged. Props aristath. See #50328. git-svn-id: https://develop.svn.wordpress.org/trunk@49850 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
91a6444e50
commit
3d43e57237
@ -71,6 +71,14 @@ function remove_block_asset_path_prefix( $asset_handle_or_path ) {
|
||||
* @return string Generated asset name for the block's field.
|
||||
*/
|
||||
function generate_block_asset_handle( $block_name, $field_name ) {
|
||||
if ( 0 === strpos( $block_name, 'core/' ) ) {
|
||||
$asset_handle = str_replace( 'core/', 'wp-block-', $block_name );
|
||||
if ( 0 === strpos( $field_name, 'editor' ) ) {
|
||||
$asset_handle .= '-editor';
|
||||
}
|
||||
return $asset_handle;
|
||||
}
|
||||
|
||||
$field_mappings = array(
|
||||
'editorScript' => 'editor-script',
|
||||
'script' => 'script',
|
||||
|
||||
@ -144,6 +144,30 @@ class WP_Test_Block_Register extends WP_UnitTestCase {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 50328
|
||||
*/
|
||||
function test_generate_block_asset_handle_core_block() {
|
||||
$block_name = 'core/paragraph';
|
||||
|
||||
$this->assertSame(
|
||||
'wp-block-paragraph-editor',
|
||||
generate_block_asset_handle( $block_name, 'editorScript' )
|
||||
);
|
||||
$this->assertSame(
|
||||
'wp-block-paragraph',
|
||||
generate_block_asset_handle( $block_name, 'script' )
|
||||
);
|
||||
$this->assertSame(
|
||||
'wp-block-paragraph-editor',
|
||||
generate_block_asset_handle( $block_name, 'editorStyle' )
|
||||
);
|
||||
$this->assertSame(
|
||||
'wp-block-paragraph',
|
||||
generate_block_asset_handle( $block_name, 'style' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 50263
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user