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

Blocks: Align with Gutenberg the name of generated asset handle for core blocks #820

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/wp-includes/blocks.php
Expand Up @@ -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',
Expand Down
24 changes: 24 additions & 0 deletions tests/phpunit/tests/blocks/register.php
Expand Up @@ -144,6 +144,30 @@ function test_generate_block_asset_handle() {
);
}

/**
* @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
*/
Expand Down