Make WordPress Core

Changeset 49850


Ignore:
Timestamp:
12/21/2020 11:37:30 AM (3 years ago)
Author:
gziolo
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks.php

    r49695 r49850  
    7272 */
    7373function generate_block_asset_handle( $block_name, $field_name ) {
     74    if ( 0 === strpos( $block_name, 'core/' ) ) {
     75        $asset_handle = str_replace( 'core/', 'wp-block-', $block_name );
     76        if ( 0 === strpos( $field_name, 'editor' ) ) {
     77            $asset_handle .= '-editor';
     78        }
     79        return $asset_handle;
     80    }
     81
    7482    $field_mappings = array(
    7583        'editorScript' => 'editor-script',
  • trunk/tests/phpunit/tests/blocks/register.php

    r49603 r49850  
    141141        $this->assertSame(
    142142            'unit-tests-my-block-style',
     143            generate_block_asset_handle( $block_name, 'style' )
     144        );
     145    }
     146
     147    /**
     148     * @ticket 50328
     149     */
     150    function test_generate_block_asset_handle_core_block() {
     151        $block_name = 'core/paragraph';
     152
     153        $this->assertSame(
     154            'wp-block-paragraph-editor',
     155            generate_block_asset_handle( $block_name, 'editorScript' )
     156        );
     157        $this->assertSame(
     158            'wp-block-paragraph',
     159            generate_block_asset_handle( $block_name, 'script' )
     160        );
     161        $this->assertSame(
     162            'wp-block-paragraph-editor',
     163            generate_block_asset_handle( $block_name, 'editorStyle' )
     164        );
     165        $this->assertSame(
     166            'wp-block-paragraph',
    143167            generate_block_asset_handle( $block_name, 'style' )
    144168        );
Note: See TracChangeset for help on using the changeset viewer.