Make WordPress Core


Ignore:
Timestamp:
09/14/2022 10:50:26 AM (2 years ago)
Author:
gziolo
Message:

Blocks: Allow registering multiple items for all supported asset types

Follow-up #54337, [52069]. Part of https://github.com/WordPress/gutenberg/issues/41236. More details in https://github.com/WordPress/gutenberg/issues/33542.

Allow passing more than one script per block for editorScript, script, and viewScript fields in the block.json metadata file. This aligns with the previously added changes for style and editorStyle fields.

This change impacts the WP_Block_Type class and the REST API endpoint for block types. To ensure backward compatibiliy old names were soft deprecated in favor of new fields that work with array values and have _handles suffix.

Props zieladam, dlh, timothyblynjacobs, aristath, bernhard-reiter.
Fixes #56408.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-block-type-controller.php

    r54058 r54155  
    238238        $this->assertSame( '1', $data['description'] );
    239239        $this->assertNull( $data['icon'] );
    240         $this->assertNull( $data['editor_script'] );
    241         $this->assertNull( $data['script'] );
    242         $this->assertNull( $data['view_script'] );
    243         $this->assertNull( $data['editor_style'] );
    244         $this->assertNull( $data['style'] );
     240        $this->assertSameSets( array(), $data['editor_script_handles'] );
     241        $this->assertSameSets( array(), $data['script_handles'] );
     242        $this->assertSameSets( array(), $data['view_script_handles'] );
     243        $this->assertSameSets( array(), $data['editor_style_handles'] );
     244        $this->assertSameSets( array(), $data['style_handles'] );
    245245        $this->assertSameSets( array(), $data['provides_context'] );
    246246        $this->assertSameSetsWithIndex(
     
    261261        $this->assertFalse( $data['is_dynamic'] );
    262262        $this->assertSameSets( array( array() ), $data['variations'] );
     263        // Deprecated properties.
     264        $this->assertNull( $data['editor_script'] );
     265        $this->assertNull( $data['script'] );
     266        $this->assertNull( $data['view_script'] );
     267        $this->assertNull( $data['editor_style'] );
     268        $this->assertNull( $data['style'] );
     269
    263270    }
    264271
     
    300307        $this->assertSame( '', $data['description'] );
    301308        $this->assertNull( $data['icon'] );
    302         $this->assertNull( $data['editor_script'] );
    303         $this->assertNull( $data['script'] );
    304         $this->assertNull( $data['view_script'] );
    305         $this->assertNull( $data['editor_style'] );
    306         $this->assertNull( $data['style'] );
     309        $this->assertSameSets( array(), $data['editor_script_handles'] );
     310        $this->assertSameSets( array(), $data['script_handles'] );
     311        $this->assertSameSets( array(), $data['view_script_handles'] );
     312        $this->assertSameSets( array(), $data['editor_style_handles'] );
     313        $this->assertSameSets( array(), $data['style_handles'] );
    307314        $this->assertSameSetsWithIndex(
    308315            array(
     
    324331        $this->assertFalse( $data['is_dynamic'] );
    325332        $this->assertSameSets( array(), $data['variations'] );
     333        // Deprecated properties.
     334        $this->assertNull( $data['editor_script'] );
     335        $this->assertNull( $data['script'] );
     336        $this->assertNull( $data['view_script'] );
     337        $this->assertNull( $data['editor_style'] );
     338        $this->assertNull( $data['style'] );
    326339    }
    327340
     
    393406        $data       = $response->get_data();
    394407        $properties = $data['schema']['properties'];
    395         $this->assertCount( 23, $properties );
     408        $this->assertCount( 28, $properties );
    396409        $this->assertArrayHasKey( 'api_version', $properties );
    397410        $this->assertArrayHasKey( 'title', $properties );
     
    406419        $this->assertArrayHasKey( 'category', $properties );
    407420        $this->assertArrayHasKey( 'is_dynamic', $properties );
    408         $this->assertArrayHasKey( 'editor_script', $properties );
    409         $this->assertArrayHasKey( 'script', $properties );
    410         $this->assertArrayHasKey( 'view_script', $properties );
    411         $this->assertArrayHasKey( 'editor_style', $properties );
    412         $this->assertArrayHasKey( 'style', $properties );
     421        $this->assertArrayHasKey( 'editor_script_handles', $properties );
     422        $this->assertArrayHasKey( 'script_handles', $properties );
     423        $this->assertArrayHasKey( 'view_script_handles', $properties );
     424        $this->assertArrayHasKey( 'editor_style_handles', $properties );
     425        $this->assertArrayHasKey( 'style_handles', $properties );
    413426        $this->assertArrayHasKey( 'parent', $properties );
    414427        $this->assertArrayHasKey( 'example', $properties );
     
    417430        $this->assertArrayHasKey( 'variations', $properties );
    418431        $this->assertArrayHasKey( 'ancestor', $properties );
     432        // Deprecated properties.
     433        $this->assertArrayHasKey( 'editor_script', $properties );
     434        $this->assertArrayHasKey( 'script', $properties );
     435        $this->assertArrayHasKey( 'view_script', $properties );
     436        $this->assertArrayHasKey( 'editor_style', $properties );
     437        $this->assertArrayHasKey( 'style', $properties );
     438
    419439    }
    420440
     
    519539            'name',
    520540            'category',
    521             'editor_script',
    522             'script',
    523             'view_script',
    524             'editor_style',
    525             'style',
     541            'editor_script_handles',
     542            'script_handles',
     543            'view_script_handles',
     544            'editor_style_handles',
     545            'style_handles',
    526546            'title',
    527547            'icon',
     
    535555            'textdomain',
    536556            'example',
     557            // Deprecated fields.
     558            'editor_script',
     559            'script',
     560            'view_script',
     561            'editor_style',
     562            'style',
    537563        );
    538564
Note: See TracChangeset for help on using the changeset viewer.